ADVANCE PROGRAMMING LANGUGES 13-EE-78 ASSIGNMENT # 02
Runner Class (Question # 01)
Source Code:
##include<iostream.h>
#include<conio.h>
#include<stdio.h>
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=[Link];
if([Link]>y)
{y=[Link];
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=[Link]();
cout<<s_name<<" Cover the longesr Distance.\n";
getch();
}
Output:
Bank Account Management System
Source Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class Bank
{
char name[30],account_no[30],account_type[30];
int balance;
public:
bank()
{ name[0]='/0';
account_no[0]='\0';
account_type[0]='\0';
balance=0;
}
void deposit(int);
void withdraw(int);
void display();
void New();
void operator +=(Bank demo)
ADVANCE PROGRAMMING LANGUGES 13-EE-78 ASSIGNMENT # 02
{
balance=[Link]+balance;
}
};
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;
[Link]();
[Link]();
cout<<"How Much you want to deposit:";
cin>>dep;
[Link](dep);
cout<<"How much you want to withdraw:";
cin>>w_draw;
[Link](w_draw);
[Link]();
[Link]();
b2 +=b1;
cout<<"Adding object 1 to object 2......."<<endl;
[Link](); }
ADVANCE PROGRAMMING LANGUGES 13-EE-78 ASSIGNMENT # 02
Output:
Telephone Directory Management
Source Code:
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>
#include<fstream.h>
#include<stdio.h>
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;
[Link]("c:\\[Link]",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:
[Link]();
[Link](ch);
[Link]((char *)&rec,sizeof(rec));
break;
case 2:
[Link](0,ios::beg);
cout<<"\n\nRecords in Phone Book\n";
while(file)
{
[Link]((char *)&rec,sizeof(rec));
if([Link]())
[Link]();
}
ADVANCE PROGRAMMING LANGUGES 13-EE-78 ASSIGNMENT # 02
[Link](); getch();
break;
case 4:
cout<<"\n\nEnter Name:";
gets(nm);
[Link](0,ios::beg);
found=0;
while([Link]((char *)&rec,sizeof(rec)))
{
if(strcmp(nm,[Link]())==0)
{
found=1;
[Link]();
}
}
[Link]();
if(found==0);
cout<<"\n\n---Record Not Found---\n";
getch();
break;
case 3:
cout<<"\n\nEnter Telephone No.:";
cin>>telno;
[Link](0,ios::beg);
found=0;
while([Link]((char *)&rec,sizeof(rec)))
{
if(strcmp(telno,[Link]())==0)
{ found=1;
[Link]();
}
}
[Link]();
if(found==0);
cout<<"\n\n---Record Not Found---\n";
getch();
break;
case 5:
cout<<"\n\nEnter Name:";
gets(nm);
[Link](0,ios::beg);
found=0;
int cnt=0;
while([Link]((char *)&rec,sizeof(rec)))
{
cnt++;
if(strcmp(nm,[Link]())==0)
{
found=0;
break;
}
}
[Link]();
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);
[Link](ch);
if([Link]())
[Link]();
cout<<"Enter New Telephone No:";
gets(telno);
[Link](location);
[Link](nm,telno);
[Link]((char*)&rec,sizeof(rec));
[Link]();
}
break;
case 6:
goto out;
}
}
out:
[Link]();
getch();
}
Output: