Object Oriented programming
Assignment # 1
Submitted To Respected Ma’am : Nosheen Manzoor
(University of Management andTechnology)
SUBMIT BY : SANA IQBAL (F2022105195)
Object Oriented programming
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
struct record {
string first_name;
string last_name;
int phone_number;
string address;
};
record phonedir[10];
void add_Record(int obj) {
cout<<"Enter first name: ";
cin>>phonedir[obj].first_name;
cout<<"Enter last name: ";
cin>>phonedir[obj].last_name;
cout<<"Enter phone number: ";
cin>>phonedir[obj].phone_number;
cout<<"Enter address: ";
cin >>phonedir[obj].address;
}
void delete_Record(int obj) {
phonedir[obj] = {" ", " ",0, " "};
}
void update_Record(int obj) {
cout<<"Enter your new first name: ";
cin>>phonedir[obj].first_name;
cout<<"Enter new last name: ";
1
Object Oriented programming
cin>>phonedir[obj].last_name;
cout<<"Enter new phone number: ";
cin>>phonedir[obj].phone_number;
cout<<"Enter new address: ";
cin>>phonedir[obj].address;
}
int main()
{
int choose,obj;
do{
cout<<"Phone Directory"<<endl;
cout<<"1. ADD Record"<<endl;
cout<<"2. DELETE Record"<<endl;
cout<<"3. UPDATE Record"<<endl;
cout<<"4. QUIT"<<endl;
cout<<"Enter your number you choose : ";
cin >>choose;
switch (choose) {
case 1:
cout<<"Enter index From (0 to 9): ";
cin>>obj;
add_Record(obj);
break;
case 2:
cout<<"Enter index From (0 to 9): ";
cin>>obj;;
delete_Record(obj);
break;
2
Object Oriented programming
case 3:
cout<<"Enter index From (0 to 9): ";
cin>>obj;
update_Record(obj);
break;
case 4:
cout<<"Phone Directory Exiting"<<endl;
break;
default:
cout<<"Invalid choice."<<endl;
break;
}
}while(choose!=4);
cout<<"Phone Directory Record : "<<endl;
for(int j=0;j<10;j++)
{
cout<<j<<endl;
cout<<phonedir[j].first_name<<endl;
cout<<phonedir[j].last_name<<endl;
cout<<phonedir[j].phone_number<<endl;
cout<<phonedir[j].address<<endl;
}
}