A
arnuld
it works fine without any trouble. i want to have advice on improving
the code from any angle like readability, maintenance etc:
---------- PROGRAMME ------------
/* Stroustrup, 5.9, exercise 11
STATEMENT:
Read a sequence of words from the input. use "quit" as the word
to terminate the input. Print the words in the order they were
entered. don't print a word twice.modify the programme to sort the
words before printing them.
*/
#include<iostream>
#include<string>
#include<vector>
int main()
{
std::vector<std::string> collect_input;
std::string input_word;
std::cin >> input_word;
for(int i=0; input_word != "quit"; ++i)
{
collect_input.push_back(input_word);
std::cin >> input_word;
}
std::cout << "\n *** Printing WOrds ***\n";
for(unsigned int i=0; i < collect_input.size(); ++i)
std::cout << collect_input
<< '\n';
return 0;
}
----------- OUTPUT ----------------
[arch@voodo tc++pl]$ g++ -ansi -pedantic -Wall -Wextra -O
ex_5.9-11.cpp
[arch@voodo tc++pl]$ ./a.out
like this
quitting
quite
and morq quotwe FINISHED quiT quit
*** Printing WOrds ***
like
this
quitting
quite
and
morq
quotwe
FINISHED
quiT
[arch@voodo tc++pl]$
the code from any angle like readability, maintenance etc:
---------- PROGRAMME ------------
/* Stroustrup, 5.9, exercise 11
STATEMENT:
Read a sequence of words from the input. use "quit" as the word
to terminate the input. Print the words in the order they were
entered. don't print a word twice.modify the programme to sort the
words before printing them.
*/
#include<iostream>
#include<string>
#include<vector>
int main()
{
std::vector<std::string> collect_input;
std::string input_word;
std::cin >> input_word;
for(int i=0; input_word != "quit"; ++i)
{
collect_input.push_back(input_word);
std::cin >> input_word;
}
std::cout << "\n *** Printing WOrds ***\n";
for(unsigned int i=0; i < collect_input.size(); ++i)
std::cout << collect_input
<< '\n';
return 0;
}
----------- OUTPUT ----------------
[arch@voodo tc++pl]$ g++ -ansi -pedantic -Wall -Wextra -O
ex_5.9-11.cpp
[arch@voodo tc++pl]$ ./a.out
like this
quitting
quite
and morq quotwe FINISHED quiT quit
*** Printing WOrds ***
like
this
quitting
quite
and
morq
quotwe
FINISHED
quiT
[arch@voodo tc++pl]$