Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<cctype>
- #include<iomanip>
- class legoset
- {
- char setcatname[25];
- char name[50];
- char legoinclude[25];
- char legotype[25];
- public:
- void create_category();
- void show_category() const;
- void modify();
- void report() const;
- int retacno() const;
- };
- void legoset::create_category()
- {
- std::cout << "Please enter a category name : n";
- std::cin >> setcatname;
- //std::cin.getline(setcatname, 25);
- std::cout << "Please enter your username! n";
- std::cin >> name;
- std::cin.ignore();
- std::cin.getline(name, 50);
- std::cout << name << " , is it a vehicle or building (V/B)?n";
- std::cin >> legotype;
- legotype[25] = toupper(legotype[25]);
- std::cin.getline(legotype, 25);
- std::cout << "n Please enter the name of the lego set. n";
- std::cin >> legoinclude;
- //std::cin.getline(legoinclude, 25);
- std::cout << "nn Category Created Successfully!!!";
- return;
- }
- void legoset::show_category() const
- {
- std::cout << "Category : n" << setcatname;
- std::cout << "Username Of Holder n: " << name;
- std::cout << " Lego type (B/V) : " << legotype;
- std::cout << " Lego set (with details) : " << legoinclude;
- return;
- }
- void legoset::modify()
- {
- std::cout << "Category : n" << setcatname[25];
- std::cout << "nModify Holder's name : ";
- std::cin.ignore();
- std::cin.getline(name, 50);
- std::cout << "nModify A Building or vehicle class ( B/V ) : ";
- std::cin >> legotype[25];
- legotype[25] = toupper(legotype[25]);
- std::cout << "nModify Lego set (with details) : ";
- std::cin >> legoinclude[25];
- }
- void legoset::report() const
- {
- std::cout << setcatname[25] << std::setw(10) << " " << name << std::setw(10) << " " << legotype[25] << std::setw(6) << legoinclude[25] << std::endl;
- }
- int legoset::retacno() const
- {
- return setcatname[25];
- }
- void write_legoset(); //function to write record in binary file
- void display_sp(int); //function to display account details given by user
- void modify_set(int); //function to modify record of file
- void delete_set(int); //function to delete record of file
- void display_all(); //function to display all account details
- void intro(); //introductory screen function
- int main()
- {
- char choice;
- int num;
- intro();
- do
- {
- system("cls");
- std::cout << "nnntMAIN MENU";
- std::cout << "nnt01. New Category";
- std::cout << "nnt02. ADD A NEW SET";
- std::cout << "nnt03. ALL USERS HOLDER LIST";
- std::cout << "nnt04. DELETE A CATEGORY";
- std::cout << "nnt05. MODIFY A CATEGORY";
- std::cout << "nnt06. EXIT";
- std::cout << "nntSelect Your Option (1-6) ";
- std::cin >> choice;
- system("cls");
- switch (choice)
- {
- case '1':
- write_legoset();
- break;
- case '2':
- std::cout << "nntEnter The category Name : "; std::cin >> num;
- display_sp(num);
- break;
- case '3':
- display_all();
- break;
- case '4':
- std::cout << "nntEnter The Category Name : "; std::cin >> num;
- delete_set(num);
- break;
- case '5':
- std::cout << "nntEnter The Category Name : "; std::cin >> num;
- modify_set(num);
- break;
- case '6':
- std::cout << "nntThanks for using lego managemnt system!";
- std::exit;
- break;
- default: std::cout << "a";
- }
- std::cin.ignore();
- std::cin.get();
- } while (choice != '6');
- return 0;
- }
- //***************************************************************
- // function to write in file
- //****************************************************************
- void write_legoset()
- {
- legoset lego;
- std::ofstream outFile;
- outFile.open("legoset.dat", std::ios::binary | std::ios::app);
- lego.create_category();
- outFile.write(reinterpret_cast<char *> (&lego), sizeof(legoset));
- outFile.close();
- }
- //***************************************************************
- // function to read specific record from file
- //****************************************************************
- void display_sp(int n)
- {
- legoset lego;
- bool flag = false;
- std::ifstream inFile;
- inFile.open("legoset.dat", std::ios::binary);
- if (!inFile)
- {
- std::cout << "File could not be open !! Press any Key...";
- return;
- }
- std::cout << "nLEGOSET DETAILSn";
- while (inFile.read(reinterpret_cast<char *> (&lego), sizeof(legoset)))
- {
- if (lego.retacno() == n)
- {
- lego.show_category();
- flag = true;
- }
- }
- inFile.close();
- if (flag == false)
- std::cout << "nnLego set does not exist in this file";
- }
- //***************************************************************
- // function to modify record of file
- //****************************************************************
- void modify_set(int n)
- {
- bool found = false;
- legoset lego;
- std::fstream File;
- File.open("legoset.dat", std::ios::binary | std::ios::in | std::ios::out);
- if (!File)
- {
- std::cout << "File could not be open !! Press any Key...";
- return;
- }
- while (!File.eof() && found == false)
- {
- File.read(reinterpret_cast<char *> (&lego), sizeof(legoset));
- if (lego.retacno() == n)
- {
- lego.show_category();
- std::cout << "nnPlease Enter The New Details For This Category." << std::endl;
- lego.modify();
- int pos = (-1)*static_cast<int>(sizeof(legoset));
- File.seekp(pos, std::ios::cur);
- File.write(reinterpret_cast<char *> (&lego), sizeof(legoset));
- std::cout << "nnt Category Updated!";
- found = true;
- }
- }
- File.close();
- if (found == false)
- std::cout << "nn Category Not Found ";
- }
- //***************************************************************
- // function to delete record of file
- //****************************************************************
- void delete_set(int n)
- {
- legoset lego;
- std::ifstream inFile;
- std::ofstream outFile;
- inFile.open("legoset.dat", std::ios::binary);
- if (!inFile)
- {
- std::cout << "File could not be open !! Press any Key...";
- return;
- }
- outFile.open("Temp.dat", std::ios::binary);
- inFile.seekg(0, std::ios::beg);
- while (inFile.read(reinterpret_cast<char *> (&lego), sizeof(legoset)))
- {
- if (lego.retacno() != n)
- {
- outFile.write(reinterpret_cast<char *> (&lego), sizeof(legoset));
- }
- }
- inFile.close();
- outFile.close();
- remove("legoset.dat");
- rename("Temp.dat", "legoset.dat");
- std::cout << "nntCategory Deleted ..";
- }
- //***************************************************************
- // function to display all accounts deposit list
- //****************************************************************
- void display_all()
- {
- legoset lego;
- std::ifstream inFile;
- inFile.open("legoset.dat", std::ios::binary);
- if (!inFile)
- {
- std::cout << "File could not be open !! Press any Key...";
- return;
- }
- std::cout << "nnttUSER HOLDER LISTnn";
- std::cout << "====================================================n";
- std::cout << "A/c no. NAME Type Balancen";
- std::cout << "====================================================n";
- while (inFile.read(reinterpret_cast<char *> (&lego), sizeof(legoset)))
- {
- lego.report();
- }
- inFile.close();
- }
- void intro()
- {
- std::cout << "nnnt LEGOSET";
- std::cout << "nntMANAGEMENT";
- std::cout << "nnt SYSTEM";
- std::cout << "nnnnMADE BY : Philippe Barry";
- std::cin.get();
- }
- //***************************************************************
- // END OF PROJECT
- //***************************************************************
Add Comment
Please, Sign In to add comment