Advance Rogramming Languge Assignment
Advance Rogramming Languge Assignment
static double y;
class run
{
private:
char name[20];
double distance;
static int n;
public:
run()
{ n++; }
static int count()
{ return n;}
void get()
{
cout<<"Enter the Name of Runner:";
gets(name);
cout<<"How much distance is coverd by Runner(km):";
cin>>distance;
}
void show()
{
cout<<"Name of Runner :";
puts(name);
cout<<"Distance Coverd:"<<distance<<" km."<<endl;
}
static run max(run x)
{
y=x.distance;
if(x.distance>y)
{y=x.distance;
return x;}
}
char* abc()
{ return &name[0]; }
};
int run::n=0;
void main()
{
clrscr();
char* s_name;
run r[3],check;
ADVANCE PROGRAMMING LANGUGES 13-EE-78 ASSIGNMENT # 02
r[0].get();
r[1].get();
r[2].get();
r[0].show();
r[1].show();
r[2].show();
for(int repeat=0;repeat<=run::count() ;repeat++)
{
check=run::max(r[0]);
}
s_name=check.abc();
cout<<s_name<<" Cover the longesr Distance.\n";
getch();
}
Output:
void Bank::deposit(int x)
{
balance=balance+x;
cout<<"Now your New Balance is :"<<balance<<endl;
}
void Bank::withdraw(int x)
{
if(x>balance)
cout<<"You have not enogh Balance.\nYour current Balance is :"<<balance<<endl;
else
{
cout<<"You WithDraw : "<<x<<" from "<<balance;
balance=balance-x;
cout<<"\nNow Your Current Balance is :"<<balance<<endl;
}
}
void Bank::display()
{
cout<<"\t\t^^^^Account Information^^^^\n";
cout<<"Name of Coustomer :";
puts(name);
cout<<"And Your Current Balance is :"<<balance<<endl; }
void Bank::New()
{
cout<<"\t\t@@@ New Account @@@\n";
cout<<"Enter the Name of New Coustomer :"; gets(name);
cout<<"Enter Account type :"; gets(account_type);
cout<<"Enter Account number :"; gets(account_no);
cout<<"How much balance you want to deposit now :"; cin>>balance;
}
void main()
{
int dep,w_draw;
Bank b1,b2;
b1.New();
b1.display();
cout<<"How Much you want to deposit:";
cin>>dep;
b1.deposit(dep);
cout<<"How much you want to withdraw:";
cin>>w_draw;
b1.withdraw(w_draw);
b2.New();
b2.display();
b2 +=b1;
cout<<"Adding object 1 to object 2......."<<endl;
b2.display(); }
ADVANCE PROGRAMMING LANGUGES 13-EE-78 ASSIGNMENT # 02
Output:
class phonebook
{
char name[20],phno[9];
public:
void getdata();
void showdata();
char *getname()
{
return name;
}
char *getphno()
{
return phno;
}
ADVANCE PROGRAMMING LANGUGES 13-EE-78 ASSIGNMENT # 02
void update(char *nm,char *telno)
{
strcpy(name,nm);
strcpy(phno,telno);
}
};
void phonebook::getdata()
{
cout<<"\nEnter Name :";
gets(name);
cout<<"Enter Phone No.:";
gets(phno);
}
void phonebook::showdata()
{
cout<<"\n"<<setw(15)<<name;
cout<<setw(9)<<phno;
}
void main()
{
clrscr();
phonebook rec;
fstream file;
file.open("c:\\phone.dat",ios::ate|ios::in|ios::out|ios::binary);
char ch,nm[20],telno[9];
int choice,found=0;
while(1)
{
cout<<"\n****PhoneBook****\n";
cout<<"1-Add New Record\n";
cout<<"2-Display All Record\n";
cout<<"3-Search Telephone No.\n";
cout<<"4-Search Person Name\n";
cout<<"5-Update Telephone No.\n";
cout<<"6-Exit\n";
cin>>choice;
switch(choice)
{
case 1:
rec.getdata();
cin.get(ch);
file.write((char *)&rec,sizeof(rec));
break;
case 2:
file.seekg(0,ios::beg);
cout<<"\n\nRecords in Phone Book\n";
while(file)
{
file.read((char *)&rec,sizeof(rec));
if(file.eof())
rec.showdata();
}
ADVANCE PROGRAMMING LANGUGES 13-EE-78 ASSIGNMENT # 02
file.clear(); getch();
break;
case 4:
cout<<"\n\nEnter Name:";
gets(nm);
file.seekg(0,ios::beg);
found=0;
while(file.read((char *)&rec,sizeof(rec)))
{
if(strcmp(nm,rec.getname())==0)
{
found=1;
rec.showdata();
}
}
file.clear();
if(found==0);
cout<<"\n\n---Record Not Found---\n";
getch();
break;
case 3:
cout<<"\n\nEnter Telephone No.:";
cin>>telno;
file.seekg(0,ios::beg);
found=0;
while(file.read((char *)&rec,sizeof(rec)))
{
if(strcmp(telno,rec.getphno())==0)
{ found=1;
rec.showdata();
}
}
file.clear();
if(found==0);
cout<<"\n\n---Record Not Found---\n";
getch();
break;
case 5:
cout<<"\n\nEnter Name:";
gets(nm);
file.seekg(0,ios::beg);
found=0;
int cnt=0;
while(file.read((char *)&rec,sizeof(rec)))
{
cnt++;
if(strcmp(nm,rec.getname())==0)
{
found=0;
break;
}
}
file.clear();
ADVANCE PROGRAMMING LANGUGES 13-EE-78 ASSIGNMENT # 02
if(found==0)
cout<<"\n\n---Record Not Found---\n";
else
{
int location=(cnt-1)*sizeof(rec);
cin.get(ch);
if(file.eof())
file.clear();
cout<<"Enter New Telephone No:";
gets(telno);
file.seekp(location);
rec.update(nm,telno);
file.write((char*)&rec,sizeof(rec));
file.flush();
}
break;
case 6:
goto out;
}
}
out:
file.close();
getch();
}
Output: