What is the output of the following program segment? (15) vector vec = {'A', 't', 'B', 'n', 'c', '*', '9', 'r', 'h', '8' }; vector::iterator lastElem; ostream_iterator screen(cout, " "); copy(vec.begin(), vec.end(), screen); cout << endl; lastElem = remove_if(vec.begin(), vec.end(), isdigit); copy(vec.begin(), lastElem, screen); cout << endl;
Answer: 'A', 't', 'B', 'n', 'c', '*', 'r', 'h'
Explanation: The code removed the digit in vector . Hence it will print to screen all characters without digits.
PLEASE COMMENT if there is any concern.
==============================
What is the output of the following program segment? (15) vector vec = {'A', 't', 'B',...
18 C++
1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is
What is the output of the following program segment? int count = 5; while(--count > 0) cout << count << " "; cout << endl;
5. (7 pts) What wil display on the output screen after following program is executed? includeciostream using namespace std int b 40 int A function(int a) int main (void) int c 7, b 15 cout<cA function (e) <cendla return 6 int A function (int a) int i cout<<b<<endl; if (a>-0) else return i i-ai i--ai Ans5 6. (7 pts) Show what will appear on the output screen after the following program is executed tincludeciostream> using namespace std; void A function...
c++
In the following segment of the code, what will be the output if opening of the file is not successful? ifstream infile; try{ infile.open("test.txt"); if(!infile) throw -1; else cout << "successful" << endl; } catch(const char* msg) { cout << msg << " unsuccessful" << endl; } catch(int i) { cout << i < was returned, unsuccessful" <<endl; #8 WA w
5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8}; for(int i=0;i<9;i++) a[i]=a[i+1]; for(int i=0;i<8;i++) cout<<a[i]<<” “; cout<<endl; 6. What will be shown on the output screen after following statements are executed? char a[ ]="I have a part time job"; int c=x, i=0 while(a[i]!=’\0’){ if(a[i]==' '){ c++; cout<<endl; } else cout<<a[i]; i++; } cout<<c<<endl; 7. After following statements are executed, what are the outputs char a[ ]= "Fresno City College"; for (i...
consider following program segment
return 0; II: (10 pts) Show the output of the Components (not values just which members)of the 2 dimensional array B in the following loops. for (L=3; L >=1; L--) for (M=0; M < 2; M++) cout << B[L] [M] << " "; cout << endl; return 0; II: (10 pts) Show the output of the Components (not values just which members)of the 2 dimensional array B in the following loops. for (L=3; L >=1; L--)...
What is the output of the program segment? Assume there are no syntax errors and the code will compile. int i = 1; int n = 0; do { cout << i; i++; } while (i <= n); b) What are the values of i and n after execution? Assume there are no syntax errors and the code will compile. int i = 1; int n = 0; do { cout << i; i++; } while (i <= n);
What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = 0; serious = 0; } else if (funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } cout << funny << serious << endl;
Assuming the following code is part of an error-free program, what is the output on the screen vector<char> example(4,'a'); example[2]='b'; example.at(1)-c'; for (int i-0; I <example.size); i++) cout << examplelil<<""
C++ int num [ ] = { 1,2,3,3,4,5,6,7,8 } vector <int> vec (num, num + 8) ; vector <int> : : iterator iter ; iter = vec . begin ( ) ; Question 1. What is the result of execute the instruction num [4] ;? a)2 b)7 c) unknown Question 2. How many elements does the vector vec contain? a)0 b)10 c)16