Professional Documents
Culture Documents
Awais Ahmad: Assignment No 2
Awais Ahmad: Assignment No 2
Ahmad
069
ASSIGNMENT NO 2
Question # 1 void show(Books b1)
{
cout << "Accession number : " << b1.access_num;
cout << "\nAuthur name : " << b1.auth_name;
#include <iostream> cout << "\nTitle of the Book : " << b1.book_title;
#include <fstream> cout << "\nFlag : " << b1.flag;
using namespace std; }
int main() void dis(Books b1)
{ {
int product = 1,num =1,n=5; cout << "Access number of this book is : " << b1.access_num;
string st = " * ",eq = " = "; }
ofstream opfile ("file1.txt"); int main ()
for (int i=1; i<=10; i++) {
{ Books b1,b2,b3,b4,b5,b6,b7;
product =5*i ; b1.access_num =100;
num=i; b1.auth_name ="jk Rownling";
cout << "\n"; b1.book_title="Harry Potter and the philosopher stone";
opfile << n << st << num << eq << product << endl;; b1.flag= "issued";
} b2.access_num =200;
opfile.close(); b2.auth_name ="jk Rownling";
cout << "Data stored into file " << endl; b2.book_title="Fantastic beast and the crimes of grindleward";
cout << "Reading Data from the file ..........\n"; b2.flag= "issued";
ifstream ipfile ("file1.txt"); b3.access_num =300;
while (!ipfile.eof()) b3.auth_name ="Mehmat Bozdag";
{ b3.book_title="Dirilis Ertugrul";
ipfile >> n >> st >> num >> eq >> product; b3.flag= "issued";
cout << n << st << num << eq << product << endl; b4.access_num =400;
} b4.auth_name ="Hemingway";
ipfile.close(); b4.book_title="Philosophies of hemingway";
return 0; b4.flag= "issued";
} b5.access_num =110;
b5.auth_name ="nasir gernadier";
Question # 2 b5.book_title="Cricket star";
b5.flag= "Not issued";\
b6.access_num =112;
b6.auth_name ="Ahmed Bey";
#include <iostream> b6.book_title="Facts of Nature";
#include <fstream> b6.flag= "Not issued";
using namespace std;
int main() int i1,i2,i3,add,i4,i5,issue,i6;
{ int number=6;
int num; cout << "**************************************GIANT
ofstream opfile ("question_1.txt"); GIKSEN LIBRARY**************************************";
for (int i=1; i<=10; i++) cout << "\n\n\n\n 1- Display book information\n 2 - Add a new
{ book\n 3 - Display all the books in the library of a particular author";
num=i; cout << "\n 4 - Display the number of books of a particular title\n 5 -
cout << "\n"; Display the total number of books in the library ";
opfile << num << endl;; cout << "\n 6- Issue a book(If we issue a book, then its number gets
} decreased by1 and if we add a book, its number gets increased by 1)";
opfile.close(); cout << "\n\n\n\tPress the number of operation you want to
cout << "Data stored into file " << endl; perform: ";
cout << "Reading Data from the file ..........\n"; cin >> i1;
ifstream ipfile ("question_1.txt"); if (i1 == 1)
while (!ipfile.eof()) {
{ cout << "\n 1- Harry potter and the philosopher stone\n 2-
ipfile >> num ; Fantastic beast and the crimes of grindelward";
cout << num << endl; cout << "\n 3- Dirilis Ertugrul\n 4- Philosophies of Hemingway\n 5-
} Cricket Star\n 6- Facts of nature";
ipfile.close(); cout << "\n \n \n \t Enter the number of Book you want to display
return 0; information of : ";
} cin >> i2;
switch (i2)
{
case 1:
Question # 3 show(b1);
#include <iostream> break;
using namespace std; case 2:
struct Books show(b2);
{ break;
int access_num; case 3:
string auth_name; show(b3);
string book_title; cout << "Hemingway";
string flag; break;
}; case 4:
break; cout << "Cricket Star";
case 4: break;
show(b4); case 5:
break; cout << "Facts of Nature";
case 5: break;
show(b5); }
break; }
case 6: if (i1 == 4)
show(b6); {
break; cout << "\n 1- Harry potter and the philosopher stone\n 2-
} Fantastic beast and the crimes of grindelward";
} cout << "\n 3- Dirilis Ertugrul\n 4- Philosophies of Hemingway\n 5-
if(i1 == 2) Cricket Star\n 6- Facts of nature";
{ cout << "\n \n Enter the number of Book you want to Display the
cout << "\n 1- Harry potter and the philosopher stone\n 2- number : ";
Fantastic beast and the crimes of grindelward"; cin >> i6;
cout << "\n 3- Dirilis Ertugrul\n 4- Philosophies of Hemingway\n 5- switch (i6)
Cricket Star\n 6- Facts of nature"; {
cout << "\n \n Enter the number of Book you want to Add : "; case 1:
cin >> i3; dis(b1);
switch (i3) break;
{ case 1: case 2:
add=(b1.access_num) + 1; dis(b2);
cout << "book has been added and the acces number after break;
addition is : " << add; case 3:
break; dis(b3);
case 2: break;
add=(b2.access_num) + 1; case 4:
cout << "book has been added and the acces number after dis(b4);
addition is : " << add; break;
break; case 5:
case 3: dis(b5);
add=(b3.access_num) + 1; break;
cout << "book has been added and the acces number after case 6:
addition is : " << add; dis(b6);
break; break;
case 4: }
add=(b4.access_num) + 1; }
cout << "book has been added and the acces number after if(i1 == 5)
addition is : " << add; {
break; cout << "Total Number of Books are : " << number ;
case 5: }
add=(b5.access_num) + 1; if (i1 == 6)
cout << "book has been added and the acces number after {
addition is : " << add; cout << "Following are the books which are not issued : ";
break; cout << "\n 1-" <<b5.book_title << "\n 2-" << b6.book_title;
case 6: cout << " \n Enter the number of Book You want to Issue : ";
add=(b6.access_num) + 1; cin >> i5;
cout << "book has been added and the acces number after switch (i5)
addition is : " << add; {
break; case 1:
} issue = (b5.access_num)-1;
} b5.flag = "Issued";
if(i1 == 3) cout << "Book is issued and the access number is decreased : ";
{ cout << b5.access_num << "\n and the flag is changed : " << b5.flag;
cout << "\n 1- JK Rowling"; break;
cout << "\n 2- Mehmat Bozdag\n 3- Hemingway\n 4- Nasir issue = (b6.access_num)-1;
gernadier\n 5- Ahmed Bey"; b6.flag = "Issued";
cout << "\n \n Enter the number of Writer you want to show book cout << "Book is issued and the access number is decreased : ";
of : "; cout << b6.access_num << "\n and the flag is changed : " << b6.flag;
cin >> i4; break;
switch (i4) }
{ }
case 1: return 0;
cout << "\n 1- Harry potter and the Philosophers stone \n 2-
Fantastic Beast and the crimes of grindleward"; }
break;
case 2:
cout << "Dirilis Ertugrul"; remove("teacher_Data.txt");
break; rename("teacher_Data_new.txt", "teacher_Data.txt");
case 3:
Question # 4 }
void Print_teacher_data()
#include<iostream> {
#include<fstream> teacher a;
#include<cstring> ifstream fin;
#include<stdlib.h> int i=1;
using namespace std; fin.open("teacher_Data.txt");
struct teacher while(true)
{ {
string name;
int t_id; fin>>a.name;
int j_year; fin>>a.t_id;
float salary; fin>>a.j_year;
string department; fin>>a.salary;
}; fin>>a.department;
void Enter_teacher_Data()
{ if(fin.eof())break;
teacher x; cout<<"-----------Teacher # "<<i<< " DATA---------------"<<endl;
ofstream fout; cout<<"\n Teacher Name: " <<a.name;
fout.open("Student_Data.txt",ios::app); cout<<"\n Teacher ID: " << a.t_id;
cout<<"Enter Teacher Name: "; cout<<"\n Joining year: " << a.j_year;
cin>>x.name; cout<<"\n Salary "<<a.salary;
fout<<x.name<<endl; cout<<"\n Department"<<a.department << endl;
cout<<"Enter Teacher ID: ";
cin>>x.t_id;
fout<<x.t_id<<endl;
cout<<"Enter Joining year: "; i=i+1;
cin>>x.j_year; }
fout<<x.j_year<<endl; fin.close();
cout<<"Enter Salary ";
cin>>x.salary; }
fout<<x.salary<<endl; void Search_by_tid(int sr)
cout<<"Enter Department"; {
cin>>x.department; teacher a;
fout<<x.department<<endl; ifstream fin;
int i=1;
fout.close(); fin.open("teacher_Data.txt");
} while(true)
void Delete_data(int dr) {
{
teacher a; fin>>a.name;
ifstream fin; fin>>a.t_id;
ofstream fout; fin>>a.j_year;
fin>>a.salary;
fin.open("teacher_Data.txt"); fin>>a.department;
fout.open("teacehr_Data_new.txt");
while(true) if(a.t_id==sr)
{ {
fin>>a.name; cout<<"\nEnter Teacher Name: " <<a.name;
fin>>a.t_id; cout<<"\n Teacher ID: " << a.t_id;
fin>>a.j_year; cout<<"\n Joining year: " << a.j_year;
fin>>a.salary; cout<<"\n Salary "<<a.salary;
fin>>a.department; cout<<"\n Department"<<a.department << endl;
if(fin.eof()) break; break;
if(a.t_id!=dr) }
{
fout<<a.name<<endl; if(fin.eof())
fout<<a.t_id<<endl; {
fout<<a.j_year<<endl; cout<<"Not Found!!!!!"<<endl;
fout<<a.salary<<endl; break;
fout<<a.department<<endl; }
}
if(a.t_id==dr) }
{
cout<<"Record Deleted!!!!!!!"<<endl; fin.close();
}
}
} void Salary_greter_50000()
fin.close(); }
fout.close(); main()
{
{ teacher s[3];
teacher a; bool counti = true;
ifstream fin; int ch;
int i=1; while(counti)
fin.open("teacher_Data.txt"); {
while(true)
{ cout<<"=======Welcome to teacher Management
System======="<<endl;
fin>>a.name; cout<<"SMS FUNCTIONS: "<<endl;
fin>>a.t_id; cout<<"1- Enter Teacher Data: "<<endl;
fin>>a.j_year; cout<<"2- Print Teacher Data: "<<endl;
fin>>a.salary; cout<<"3- Search Teacher by ID: "<<endl;
fin>>a.department; cout<<"4- Search Teacher by Name: "<<endl;
cout<<"5- Delete Teacher by ID: "<<endl;
if(a.salary<50000) cout<<"8- Search teacher salary greater than 50,000: " << endl;
{ cout<<"6- Clear Screen: "<<endl;
cout<<"\n Teacher Name: " <<a.name; cout<<"7- Exit "<<endl;
cout<<"\n Teacher ID: " << a.t_id; cout<<"Enter You Choice: ";
cout<<"\n Joining year: " << a.j_year; cin>>ch;
cout<<"\nSalary "<<a.salary; char ch1;
cout<<"\n Department"<<a.department << endl; if(ch==1)
break; {
} while(true)
{
if(fin.eof()) Enter_teacher_Data();
{ cout<<"Do you want enter data for another teacher (Y/N):";
cout<<"Not Found!!!!!"<<endl; cin>>ch1;
break; if(ch1=='N') break;
}
}
}
}
fin.close();
else if(ch==2)
} {
void Search_by_Name(string sn) Print_teacher_data();
{ }
teacher a;
ifstream fin; else if(ch==3)
int i=1; {
fin.open("teacher_Data.txt"); int sbr;
while(true) cout<<"Enter ID to Search teacher Record: ";
{ cin>>sbr;
Search_by_tid(sbr);
fin>>a.name;
fin>>a.t_id; }
fin>>a.j_year; else if(ch==4)
fin>>a.salary; {
fin>>a.department; string sname;
cout<<"Enter Name to Search teacher Record: ";
if(a.name==sn) cin>>sname;
{ Search_by_Name(sname);
cout<<"\n Teacher Name: " <<a.name;
cout<<"\n Teacher ID: " << a.t_id; }
cout<<"\n Joining year: " << a.j_year;
cout<<"\n Salary "<<a.salary; else if(ch==5)
cout<<"\n Department"<<a.department << endl; {
break; int dr;
} cout<<"Enter ID to Delete teacher Record: ";
cin>>dr;
if(fin.eof()) Delete_data(dr);
{
cout<<"Not Found!!!!!"; }
break; else if(ch==8)
{
} Salary_greter_50000();
}
} else if(ch==6)
fin.close();
{
system("CLS");
}
else if(ch==7)
{
break;
}
else
{
cout<<"Wrong Entry!!!!! Enter Again "<<endl;
}
}
cout<<"GOOD BYE";
}