vect1.cpp 877 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // vect1.cpp -- introducing the vector template
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. const int NUM = 5;
  6. int main()
  7. {
  8. using std::vector;
  9. using std::string;
  10. using std::cin;
  11. using std::cout;
  12. using std::endl;
  13. vector<int> ratings(NUM);
  14. vector<string> titles(NUM);
  15. cout << "You will do exactly as told. You will enter\n"
  16. << NUM << " book titles and your ratings (0-10).\n";
  17. int i;
  18. for (i = 0; i < NUM; i++)
  19. {
  20. cout << "Enter title #" << i + 1 << ": ";
  21. getline(cin,titles[i]);
  22. cout << "Enter your rating (0-10): ";
  23. cin >> ratings[i];
  24. cin.get();
  25. }
  26. cout << "Thank you. You entered the following:\n"
  27. << "Rating\tBook\n";
  28. for (i = 0; i < NUM; i++)
  29. {
  30. cout << ratings[i] << "\t" << titles[i] << endl;
  31. }
  32. // cin.get();
  33. return 0;
  34. }