In: Computer Science
In C++, create two vectors, one a vector of ints and one a vector of strings. The user will fill each one with data, and then your program will display the values.
Sample Output
The following is an example of output for this program:
Enter int: 3
Enter int: 12
Enter int: 4
Enter int: 0
Your list is:
3
12
4
Enter string: The
Enter string: quick
Enter string: brown
Enter string: fox
Enter string: jumps
Enter string: over
Enter string: the
Enter string: lazy
Enter string: dog
Enter string: quit
Your list is:
The
quick
brown
fox
jumps
over
the
lazy
dog
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> nums;
vector<string> words;
int inpNum;
string inpWord;
cout << endl;
do
{
cout << "Enter int: ";
cin >> inpNum;
if(inpNum == 0)
break;
else
nums.push_back(inpNum);
}while(inpNum != 0);
// display all the integers
cout << "Your list is:\n";
for(int i = 0; i < nums.size(); i++)
{
cout << nums[i] << endl;
}
cout << endl;
do
{
cout << "Enter string: ";
cin >> inpWord;
if(inpWord.compare("quit") == 0)
break;
else
words.push_back(inpWord);
}while(inpWord.compare("quit") != 0);
// display all the strings
cout << "Your list is:\n";
for(int i = 0; i < words.size(); i++)
{
cout << words[i] << endl;
}
cout << endl;
return 0;
}
****************************************************************** SCREENSHOT *********************************************************