Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Describe every line of the given code (also describe output) for Viva Sample run: Project code Question: Given a string s consisting of some words

Describe every line of the given code (also describe output) for Viva

Sample run:

image text in transcribed

Project code Question:

Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only.

Answer:

Project Code :

#include

#include

using namespace std;

//assume this value

int main()

{

//get the string string

str ="hello poly awesome";

//store the length of last word

int lastLength=0;

//store index

int index=0;

//loop for complete string

for(unsigned int i=0;i

//if current is sapce

if(str[i]==' '){

//if index is not zero

if(index!=0){

//set last length to index

lastLength = index;

}

index=0;

}else{

index++;

}

}

if(index!=0){

lastLength = index;

}

cout

return 0;

}

CPP_Workspace.exe C/C++ Application) K: The length of the last word is : 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago