basic c++ Can someone help with the below program in the simplest form possible
ID: 3573393 • Letter: B
Question
basic c++
Can someone help with the below program in the simplest form possible using only complex conditionals, for or while loops, functions, or arrays. We quickly learned about vectors so I'm not sure if that is what is required to get the below output?
Write a program that reads in names from stdin. Stop reading names when the name is "***DONE***". There will not be more than 100 names, although there may be way fewer. Next, display the second half of the list as shown below:
Reading: Charles
Reading: Debbie
Reading: Larry
Reading: Jerry
Reading: Elaine
Reading: Frank
Reading: George
Reading: Harry
Reading: Adam
Reading: Igor
Reading Betty Ann
Reading ***DONE***
There are 11 names in the list
Listing names 5 through 20
-> Frank
-> George
-> Harry
-> Adam
-> Igor
-> Betty Ann
Explanation / Answer
#include<iostream>
#include<string>
//max 100 names
#define MAX 100
using namespace std;
int main()
{
//declare array of string to hold names
string name[MAX];
//declare variable to cound number of names entered
int count = 0;
char ch;
//take input till user enter CTRL+Z ie EOF
while (!cin.eof())
{
cout << "Reading: ";
cin >> name[count++];
fflush(stdin);
}
cout << "Reading ***DONE***" << endl;
cout << "There are " << count-1 << " names in the list" << endl;
//display name from 5 through 20 using for loop
for (int i = 5; i <= 20; i++)
{
if (name[i] != "")
cout << "->" << name[i] << endl;
}
}
--------------------------------------------------------------------
output
Reading: Charles
Reading: Debbie
Reading: Larry
Reading: Jerry
Reading: Elaine
Reading: Frank
Reading: George
Reading: Harry
Reading: Adam
Reading: Igor
Reading: Betty Ann
Reading: ^Z
Reading ***DONE***
There are 11 names in the list
->Frank
->George
->Harry
->Adam
->Igor
->Betty
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.