Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- void classmates();
- void add();
- void update();
- void delet();
- int main() {
- int option;
- classmates();
- cout << "---------------------------------------- \n";
- cout << " CLASSMATE NAMES \n\n choose options: ";
- cout << "\n [1] add";
- cout << "\n [2] update";
- cout << "\n [3] delete";
- cout << "\n Enter your option: ";
- cin >> option;
- switch (option) {
- case 1:
- cout << "---------------------------------------- \n";
- cout << " ADD NAMES \n\n";
- add();
- classmates();
- break;
- case 2:
- cout << "---------------------------------------- \n";
- cout << " UPDATE NAMES \n\n";
- update();
- classmates();
- break;
- case 3:
- cout << "---------------------------------------- \n";
- cout << " DELETE NAMES \n\n";
- delet();
- classmates();
- break;
- default:
- cout << "Input is Invalid. Mismatch. \n";
- }
- return 0;
- }
- void add(){
- string line;
- fstream tex;
- cout << "Enter New Classmates: ";
- cin >> line;
- tex.open("tex.txt", ios::app);
- tex << "\n" << line;
- tex.close();
- }
- void classmates() {
- string line;
- fstream classmates;
- classmates.open("tex.txt");
- while (getline(classmates, line)) {
- cout << line << "\n";
- }
- classmates.close();
- }
- void update() {
- string line, up, rep;
- fstream classmates;
- cout << "Find: ";
- cin >> up;
- cout << "Replace: ";
- cin >> rep;
- classmates.open("tex.txt", ios::in);
- while (getline(classmates, line)) {
- if (line.find(up)) {
- cout << "\n" << rep;
- }
- }
- classmates.close();
- }
- void delet() {
- string line, up, rep;
- fstream classmates;
- classmates.open("tex.txt", ios::out);
- while (getline(classmates, line)) {
- cout << "\n";
- }
- classmates.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement