All About C++

Get Pure Concepts of C++

Tuesday, 9 February 2016

C++ Project on Sim Management very easy to understanding


Sim Management Project

#include<iostream>
#include<fstream>
#include<Windows.h>
#include<stdio.h>
using namespace std;
class sim
{
private:
int simno;
int total;
int cnic_no;
int day;
int month;
int year;
char customer_firstname[20];
char customer_lastname[40];
public:
          sim():total(0)
          {}
          void open_new()
          {cout<<"ENTER SIM NUMBER :"<<endl;
          cin>>simno;
          cout<<"ENTER FIRST NAME OF CUSTOMER WHO WANT TO PURCHASE NEW SIM: "<<endl;
          cin>>customer_firstname;
          cout<<"ENTER LAST NAME OF CUSTOMER :"<<endl;
          cin>>customer_lastname;
          cout<<"ENTER CNIC NO. OF CUSTOMER: "<<endl;
          cin>>cnic_no;
          cout<<"ENTER DATE OF ISSUE SIM :"<<endl<<"ENTER DAY  :"<<endl;
          cin>>day;
          cout<<"ENTER MONTH :"<<endl;
          cin>>month;
          cout<<"ENTER YEAR  :"<<endl;
          cin>>year;
          }
          void show_simacount()
          {cout<<"_______SIM ACOUNT STATUS IS_______"<<endl;
          cout<<"sim no. is :"<<simno<<endl;
          cout<<"name of customer is :"<<customer_firstname<<" "<<customer_lastname<<endl;
          cout<<"CNIC no. is :"<<cnic_no<<endl;
          cout<<"date of issue :"<<day<<"/"<<month<<"/"<<year<<endl;}
          void modify_account()
          {cout<<"SIM NO. IS :"<<simno<<endl;
          cout<<"enter modify first name of customer : "<<endl;
          cin>>customer_firstname;
          cout<<"enter modigy last name of customer:"<<endl;
          cin>>customer_lastname;
          cout<<"ENTER modify CNIC NO. OF CUSTOMER: "<<endl;
          cin>>cnic_no;
          cout<<"ENTER MODIFY DATE OF ISSUE SIM :"<<endl<<"ENTER DAY  :"<<endl;
          cin>>day;
          cout<<"ENTER MODIFY MONTH :"<<endl;
          cin>>month;
          cout<<"ENTER MODIFY YEAR  :"<<endl;
          cin>>year;
          }
          int retsimno()
          {return simno;}
};
          fstream fp;
sim azz;
void write_sim()
{
fp.open("sim.dat",ios::out|ios::app);
azz.open_new();
fp.write((char*)&azz,sizeof(sim));
fp.close();
}
void display_sp()
{
int n;
cout<<"\n\n====SIM DETAILS====";
cout<<"\n\nEnter the SIM Number : ";
cin>>n;
int flag=0;
fp.open("sim.dat",ios::in);
while(fp.read((char*)&azz,sizeof(sim)))
{
          if(azz.retsimno()==n)
{
          azz.show_simacount();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<"\n\nSIM Number does not exist"<<endl;
system("pause");
}
void modify_account()
{
int no,found=0;
cout<<"\n\n====MODIFY RECORD====";
cout<<"\n\nEnter the SIM  No. : ";
cin>>no;
fp.open("sim.dat",ios::in|ios::out);
while(fp.read((char*)&azz,sizeof(sim)) && found==0)
{
          if(azz.retsimno()==no)
{
          azz.show_simacount();
cout<<"5\n\n\n—-Enter the New Details—-\n";
azz.open_new();
int pos=-1*sizeof(azz);
fp.seekp(pos,ios::cur);
fp.write((char*)&azz,sizeof(sim));
cout<<"\n\n\t Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<"\n\n Record Not Found "<<endl;
system("pause");
}
void delete_account()
{
int no;
cout<<"\n\n====Delete Record===="<<endl;
cout<<"\n\nEnter The SIM No. : ";
cin>>no;
fp.open("sim.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&azz,sizeof(sim)))
{
          if(azz.retsimno()!=no)
{
fp2.write((char*)&azz,sizeof(sim));
}
}
fp2.close();
fp.close();
remove("sim.dat");
rename("Temp.dat","sim.dat");
cout<<"\n\n\tRecord Deleted .."<<endl;
system("pause");
}
void display_all()
{
fp.open("sim.dat",ios::in);
cout<<"\n\n\t\tSIM HOLDER LIST\n\n";
cout<<"====================================================\n";
cout<<"Sim No.\tNAME\t\tFather Name\t\tCNIC No.\n etc.\n";
cout<<"====================================================\n";
while(fp.read((char*)&azz,sizeof(sim)))
{
          azz.show_simacount();
}
fp.close();
system("pause");
}
void intro()
{system("color 15");
cout<<endl<<endl<<endl<<"===============";
Sleep(500);
cout<<"SIM=====";
Sleep(500);
cout<<"MANAGEMENT=====";
Sleep(500);
cout<<"SYSTEM";
Sleep(500);
cout<<"==============="<<endl<<endl;
Sleep(500);
cout<<"MADE BY :"<<endl;
Sleep(500);
cout<<"      Muhammad Azeem"<<endl;
Sleep(500);
cout<<"      Ali Raza"<<endl;
Sleep(500);
cout<<"      Haseeb Rana"<<endl;
Sleep(500);
cout<<"STUDENTS AT COMSATS SAHIWAL"<<endl;
Sleep(500);
cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
}
void main()
{int ch;
intro();
Sleep(700);
do
{system("color C0");
cout<<"\n\tMAIN MENU";
cout<<"\n\n\tPRESS 1. TO ISSUE NEW SIM" ;
cout<<"\n\n\tPRESS 2. SIM ENQUIRY";
cout<<"\n\n\tPRESS 3. ALL SIM HOLDER LIST";
cout<<"\n\n\tPRESS 4. TO REMOVE A SIM ";
cout<<"\n\n\tPRESS 5. TO MODIFY REGISTERATION OF A SIM";
cout<<"\n\n\tPRESS 6. EXIT";
cout<<"\n\n\tPRESS Select Your Option (1-6) "<<endl;
cin>>ch;
system("color 46");
system("cls");
switch(ch)
{
case 1: 
          system("color 90");
          write_sim();
          system("cls");
break;
case 2:
          system("color 46");
          display_sp();
          system("cls");
break;
case 3: 
          system("color 27");
          display_all();
          system("cls");
break;
case 4:
          system("color 4B");
          delete_account();
          system("cls");
break;
case 5:
          system("color B6");
          modify_account();
          system("cls");
break;
case 6:
          system("color AC");
          exit(0);
          system("cls");
default : cout<<"YOU ENTERED A WRONG INTIGER  "<<endl;
         
}}

while(ch!=6);
system("Pause");}