Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. class ReadSp {
  9. private:
  10.     vector<string> name;
  11.     vector<double> paramA;
  12.     vector<double> paramB;
  13.    
  14. public:
  15.     void addName(string nm) {name.push_back(nm);};
  16.     string getName(int ind) {return name[ind];};
  17.  
  18.     void addParamA(double a) {paramA.push_back(a);};
  19.     double getParamA(int ia) {return paramA[ia];}; 
  20.  
  21.     void addParamB(double b) {paramB.push_back(b);};
  22.     double getParamB(int ib) {return paramB[ib];}; 
  23.  
  24.     int non() {return name.size();};
  25. };
  26.  
  27. int main () {
  28.     ReadSp sp1;
  29.     string nn;
  30.     double A;
  31.     double B;
  32.     ifstream fin;
  33.     fin.open("sprav.txt");
  34.     while (!fin.eof()) {
  35.         fin >> nn >> A >> B;
  36.         sp1.addName(nn);
  37.         sp1.addParamA(A);
  38.         sp1.addParamB(B);
  39.     }
  40.     fin.close();
  41.     cout << "Загружено элементов: " << sp1.non() << endl;
  42.     cout << "Введите индекс: ";
  43.     int index;
  44.     cin >> index;
  45.     cout << sp1.getName(index) << endl;
  46.     cout << sp1.getParamA(index) << endl;
  47.     cout << sp1.getParamB(index) << endl;
  48.     return 0;
  49. }
  50.  
  51. ***
  52. файл sprav.txt
  53. ASDx6   120 12.5
  54. QWpp4   112 10.5
  55. ZXp09   100 10
  56. TTT 123 23
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement