Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <fstream>
- #include <sstream>
- #include <list>
- #include <iterator>
- #include <cstdlib>
- #include <math.h>
- #include <set>
- using namespace std;
- void view()
- {
- ifstream in("C:\\newfile.txt");
- list<string> lines;
- while(!in.eof())
- {
- string temp;
- getline(in, temp, '\n');
- if(temp != "")
- lines.push_back(temp);
- }
- for (string x : lines)
- cout << x << endl;
- in.close();
- }
- string sum(string temp)
- {
- vector<string> tokens;
- istringstream iss(temp);
- copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter(tokens));
- double sum = 0;
- for (int i = tokens.size()-1 ; i >= 4; i--)
- {
- string a = tokens[i];
- sum = sum + atoi(a.c_str());
- }
- sum /= 4;
- temp = temp + " " + to_string(sum);
- return temp;
- };
- void add()
- {
- ifstream in("C:\\newfile.txt");
- list<string> lines;
- while(!in.eof())
- {
- string temp;
- getline(in, temp, '\n');
- if(temp != "")
- lines.push_back(temp);
- }
- string temp;
- cout << "Vvedite studenta: " << endl;
- cin.get();
- getline(cin, temp, '\n');
- temp = sum(temp);
- lines.push_back(temp);
- ofstream out("C:\\newfile.txt");
- copy(lines.begin(), lines.end(), ostream_iterator<string> (out, "\n"));
- in.close();
- out.close();
- cout << "dobavlen" << endl;
- }
- void edit()
- {
- ifstream in("C:\\newfile.txt");
- vector<string> lines;
- while(!in.eof())
- {
- string temp;
- getline(in, temp, '\n');
- if(temp != "")
- lines.push_back(temp);
- }
- cout << "VVedite nomer studenta kotorogo xotite izmenit': ";
- int num;
- cin >> num;
- for (int i = 0; i < lines.size(); i++)
- {
- if(i == num-1)
- {
- string temp;
- cin.get();
- getline(cin, temp);
- temp = sum(temp);
- lines[i] = temp;
- }
- }
- ofstream out("C:\\newfile.txt");
- copy(lines.begin(), lines.end(), ostream_iterator<string> (out, "\n"));
- in.close();
- out.close();
- }
- void find()
- {
- ifstream in("C:\\newfile.txt");
- vector<string> lines;
- while(!in.eof())
- {
- string temp;
- getline(in, temp, '\n');
- if(temp != "")
- lines.push_back(temp);
- }
- cout << "VVedite nomer groupi: ";
- int group;
- cin >> group;
- set<string> findResult;
- for (int i = 0; i < lines.size(); i++)
- {
- string temp;
- temp = lines[i];
- vector<string> tokens;
- istringstream iss(temp);
- copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter(tokens));
- for (int i = 0; i < tokens.size(); i++)
- {
- if( tokens[2] == to_string(group) && (tokens[i] == "0"|| tokens[i] == "1"|| tokens[i] == "2"||tokens[i] == "3" ))
- {
- findResult.insert(temp);
- }
- }
- }
- for (string x : findResult)
- cout << x << endl;
- ofstream out("C:\\out.txt");
- copy(findResult.begin(), findResult.end(), ostream_iterator<string> (out, "\n"));
- in.close();
- out.close();
- }
- int main()
- {
- int a;
- cout << "1 - VIEW, 2 - ADD, 3 - EDIT, 4 - FIND" << endl;
- cout << "choise: ";
- while(true)
- {
- cin >> a;
- switch (a)
- {
- case 1:
- view();
- break;
- case 2:
- add();
- break;
- case 3:
- edit();
- break;
- case 4:
- find();
- break;
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement