waiting...'s Blog

vector_平行向量

 

  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.         vector<string> names;
  9.         vector<double> prices;
  10.         vector<int> scores;
  11.  
  12.         bool more = true;
  13.         string name;
  14.         double price;
  15.         int score;
  16.         string remainder, answer;
  17.         while (more)
  18.         {
  19.                 cout << "Please enter the name: ";
  20.                 cin >> name;
  21.                 names.push_back(name);
  22.                 cout << "Please enter the price: ";
  23.                 cin >> price;
  24.                 prices.push_back(price);
  25.                 cout << "Please enter the score: ";
  26.                 cin >> score;
  27.                 scores.push_back(score);
  28.                 getline(cin, remainder);
  29.                 cout << "Do you want enter more information(y/n): ";
  30.                 getline(cin, answer);
  31.                 if (answer != "y" && answer != "Y")
  32.                         more = false;
  33.         }
  34.  
  35.         for (unsigned int i = 0; i < names.size(); i++)
  36.                 cout << names[i] << " " << prices[i] << " " << scores[i] << endl;
  37.         return 0;
  38. }




Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee