Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- main()
- {
- char name [30], answer;
- char yesno;
- int age, enter;
- string surname = "";
- string search;
- ofstream myfile;
- ifstream inFile;
- string line;
- cout << "Would you like to search a user? Y/N";
- getline (char, yesno);
- yesno = toupper (yesno);
- if (yesno == 'Y'){
- cout << "To proceed, please enter your information.";
- } else if (yesno == 'N'){
- cout << "You still need to enter your information.";
- }
- cout << "What is your first name? ";
- cin.getline (name, 29);
- cout << "What's your surname? ";
- getline(cin, surname);
- cout << "Hi " << name << " " << surname;
- cout << ", what is your age? ";
- cin >> age;
- if (age <= 10) {
- cout<< "You are too young to use this program.";
- } else if (age > 10) {
- cout << "You may continue as you are over 10 years old.\n";
- cout << " Your name is " << name << " " << surname;
- cout << "\n";
- cout << "Would you like to save your data? Y/N ";
- cin >> answer;
- answer = toupper (answer);
- if (answer == 'Y'){
- cout << "Good job for participating in the the Information Leak Project.\n";
- cout << "\nIs this the correct information?\n";
- cout << "Your name is " << name << " " << surname;
- cout << "\nYour age is " << age;
- cout << "\nYou are nice :)";
- myfile.open ( "data.txt", fstream::app);
- myfile << "\nName:" << name << " " << surname << "\nAge:" << age ;
- myfile.close();
- inFile.open("data.txt");
- cout << "\nYou may now search a user\n";
- cout << "\nEnter a students first or last name\n";
- getline (cin, search);
- size_t pos;
- while(inFile.good())
- {
- getline(inFile,line); // get line from file
- pos=line.find(search); // search
- if(pos!=string::npos) // string::npos is returned if string is not found
- {
- cout <<"Found!";
- break;
- }
- }
- } else if (answer == 'N'){
- cout << "\nHahaha, you can't escape. *sending data to Information Leak Project HQ";
- cout << "\nIs this the correct information?";
- cout << "\nYour name is " << name << " " << surname;
- cout << "\nYour age is " << age;
- cout << "\nYou are an evil maniac who didn't want to participate in the I.L.P (Information Leak Project), but your not alone because so are we.";
- cout << "\n Don't worry, no data has been saved, we respect your privacy.";
- }
- cout << "\nPress enter to exit.";
- cin.ignore();
- cin.get();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment