Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Write blocks of code to perform the functions used in the following main program. bool hasNoE(string s){ /*function find - returns the index where

Question: Write blocks of code to perform the functions used in the following main program. bool hasNoE(string s){ /*function find - returns the index where "E" is from the beginning of the string, index is always positive including 0 if it has no "E", it returns -1 note: function find is not a boolean function */ if (s.find("E") == -1) return true; return false; /*if you don't know about the function find, you may use a loop for (int i = 0; i < s.length(); i++) if ( s[i] == 'E' ) return false; return true; */ } char last(string s){ return s[s.length() - 1]; //if you use function substr as s.substr(s.length()-1), then function last should return a string } void insertSpace(string &s, int i) { //Note parameter s is pass by reference, because we're updating the argument string t s.insert(i, " "); } string removeFirst(string s){ return s.substr(1); //returning partial string starting from index 1 } string longestString(string x[], int len){ string longest = x[0]; for (int i = 1; i < len; i++) if (x[i].length() > longest.length()) longest = x[i]; return longest; } int main(){ string s = "HELLO", t = "GoodBye!"; cout << hasNoE(s) << endl; //print 0 cout << last(t) << endl; //print ! insertSpace(t, 4); cout << t << endl; //print Good Bye! cout << removeFirst(s) << endl; //print EllO string x[6] = {"This", "is", "an", "easy", "question", ""}; cout << longestString(x, 6) << endl; //print question return 0; } Question: Write the output, assuming it's compiled to a.out and executed with the command ./a.out abc 123 int main(int argc, char* argv[]){ int x[5] = {2,7,1,8,2}; cout << x[3/2]*x[2] << endl; //print 7, evaluates the index of x first, 3/2 integer division is 1. x[1] is 7, x[2] is 1, 7 * 1 is 7 string words[3] = {"An ", "easy ", "question "}; for (int i = 0; i < 2; i++) cout << words[i]; cout << endl; //print An easy , for loop i starts from 0, end before 2. words[0] is An, words[1] is easy cout << words[0][0] << endl; //print A, words is an array of string, words[0] is An, [0] of string An is the first letter A string s = argv[1]; //argv store all the execuation command, argv[1] is the second word, which is abc cout << s << endl; //print abc cout << s.substr(1,2) << endl; //print bc, substr of abc, starting at index 1, 2 characters cout << argc << endl; //print 3, argc is the count of program arguments, meaning how many strings stored in argv //in this case, ./a.out is the first one, abc is the second, and 123 is the third return 0; } 

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_2

Step: 3

blur-text-image_3

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions