Guest User

Stuff

a guest
Jul 22nd, 2015
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6.  
  7. main()
  8. {
  9.     char name [30], answer;
  10.     char yesno;
  11.     int age, enter;
  12.     string surname = "";
  13.     string search;
  14.     ofstream myfile;
  15.     ifstream inFile;
  16.     string line;
  17.    
  18.   cout << "Would you like to search a user? Y/N";
  19.   getline (char, yesno);
  20.   yesno = toupper (yesno);
  21.   if (yesno == 'Y'){
  22.     cout << "To proceed, please enter your information.";
  23.   } else if (yesno == 'N'){
  24.     cout << "You still need to enter your information.";
  25.   }
  26.  
  27.   cout << "What is your first name? ";
  28.   cin.getline (name, 29);
  29.   cout << "What's your surname? ";
  30.   getline(cin, surname);
  31.   cout << "Hi " << name << " " << surname;
  32.   cout << ", what is your age? ";
  33.   cin >> age;
  34.   if (age <= 10) {
  35.   cout<< "You are too young to use this program.";
  36. } else if (age > 10) {
  37.   cout << "You may continue as you are over 10 years old.\n";
  38.   cout << " Your name is " << name << " " << surname;
  39.   cout << "\n";
  40.   cout << "Would you like to save your data? Y/N ";
  41.   cin >> answer;
  42.   answer = toupper (answer);
  43.   if (answer == 'Y'){
  44.     cout << "Good job for participating in the the Information Leak Project.\n";
  45.     cout << "\nIs this the correct information?\n";
  46.     cout << "Your name is " << name << " " << surname;
  47.     cout << "\nYour age is " << age;
  48.     cout << "\nYou are nice :)";
  49.     myfile.open ( "data.txt", fstream::app);
  50.     myfile << "\nName:" << name << " " << surname << "\nAge:" << age ;
  51.     myfile.close();
  52.     inFile.open("data.txt");
  53.     cout << "\nYou may now search a user\n";
  54.     cout << "\nEnter a students first or last name\n";
  55.     getline (cin, search);
  56.    
  57.     size_t pos;
  58. while(inFile.good())
  59.   {
  60.       getline(inFile,line); // get line from file
  61.       pos=line.find(search); // search
  62.       if(pos!=string::npos) // string::npos is returned if string is not found
  63.         {
  64.             cout <<"Found!";
  65.             break;
  66.         }
  67.   }
  68.    
  69.   } else if (answer == 'N'){
  70.     cout << "\nHahaha, you can't escape. *sending data to Information Leak Project HQ";
  71.     cout << "\nIs this the correct information?";
  72.     cout << "\nYour name is " << name << " " << surname;
  73.     cout << "\nYour age is " << age;
  74.     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.";
  75.     cout << "\n Don't worry, no data has been saved, we respect your privacy.";
  76. }
  77. cout << "\nPress enter to exit.";
  78. cin.ignore();
  79. cin.get();
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment