WAP TO ADD TWO TIME AND ADD THEM & DISPLAY THE TOTAL TIME
#include<conio.h>
#include<iostream.h>
class time
{
int hr,min;
public:
void set_time(int h,int m)
{
hr=h;
min=m;
}
void disp()
{
cout<<hr<<":"<<min;
}
void add(time,time);
};
void time::add(time t1,time t2)
{
hr=t1.hr+t2.hr;
min=t1.min+t2.min;
if(min>60)
{
hr+=1;
min-=60;
}
}
void main()
{
clrscr();
time t1,t2,t3;
t1.set_time(5,30);
t2.set_time(3,70);
t3.add(t1,t2);
t1.disp();
cout<<endl;
t2.disp();
cout<<endl;
t3.disp();
getch();
}
Monday, October 10, 2011
FUNCTIONS_4
WAP TO INPUT BANK DETAILS OF A CUSTOMER AND ALLOW WITHDRAW IF THERE IS SUFFICIENT BALANCE
FIRST METHOD
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
class bank
{
char name[10],type;
int acno;
float amt,dep,bal;
public:
void init();
void depo();
void with();
void disp();
};
void bank::init()
{
cout<<"Name::";
cin>>name;
cout<<"Enter s for savings or C for current account::";
cin>>type;
}
void bank::depo()
{
cout<<"Account no & amt to deposit::";
cin>>acno>>dep;
bal=0;
bal+=dep;
}
void bank::with()
{
cout<<"Amt to withdraw::";
cin>>amt;
if(amt>bal)
cout<<"Insufficient balance";
else
bal-=amt;
}
void bank::disp()
{
cout<<"Name::"<<name<<endl
<<"Balance::"<<bal<<endl;
}
void main()
{
clrscr();
bank b;
b.init();
b.depo();
b.with();
b.disp();
getch();
}
ANOTHER WAY TO SOLVE THE PROBLEM
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
class bank
{
char name[10],type;
int acno;
float amt,dep,bal;
public:
void init();
void depo();
void with();
void disp();
};
void bank::init()
{
cout<<"Name::";
cin>>name;
cout<<"Enter s for savings or C for current account::";
cin>>type;
}
void bank::depo()
{
cout<<"Account no & amt to deposit::";
cin>>acno>>dep;
bal=0;
bal+dep;
}
void bank::with()
{
cout<<"Amt to withdraw::";
cin>>amt;
if(amt>bal)
cout<<"Insufficient balance";
else
bal-=amt;
}
void bank::disp()
{
cout<<"Name::"<<name<<endl
<<"Balance::"<<bal<<endl;
}
void main()
{
clrscr();
bank b[10];
int ch,i,j;
for(i=1;i<=2;i++)
{
b[i].init();
}
while(1)
{
cout<<"1 to deposit"<<endl
<<"2 to withdraw"<<endl
<<"3 to deposit"<<endl
<<"4 to Exit::";
cin>>ch;
if(ch==1||ch==2||ch==3)
{
cout<<endl<<"Which customer details do you want to enter or view::";
cin>>j;
}
else
exit(1);
getch();
switch(ch)
{
case 1:
b[j].depo();
break;
case 2:
b[j].with();
break;
case 3:
b[j].disp();
break;
case 4:
exit(1);
}
getch();
}
}
FIRST METHOD
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
class bank
{
char name[10],type;
int acno;
float amt,dep,bal;
public:
void init();
void depo();
void with();
void disp();
};
void bank::init()
{
cout<<"Name::";
cin>>name;
cout<<"Enter s for savings or C for current account::";
cin>>type;
}
void bank::depo()
{
cout<<"Account no & amt to deposit::";
cin>>acno>>dep;
bal=0;
bal+=dep;
}
void bank::with()
{
cout<<"Amt to withdraw::";
cin>>amt;
if(amt>bal)
cout<<"Insufficient balance";
else
bal-=amt;
}
void bank::disp()
{
cout<<"Name::"<<name<<endl
<<"Balance::"<<bal<<endl;
}
void main()
{
clrscr();
bank b;
b.init();
b.depo();
b.with();
b.disp();
getch();
}
ANOTHER WAY TO SOLVE THE PROBLEM
#include<conio.h>#include<iostream.h>
#include<stdlib.h>
class bank
{
char name[10],type;
int acno;
float amt,dep,bal;
public:
void init();
void depo();
void with();
void disp();
};
void bank::init()
{
cout<<"Name::";
cin>>name;
cout<<"Enter s for savings or C for current account::";
cin>>type;
}
void bank::depo()
{
cout<<"Account no & amt to deposit::";
cin>>acno>>dep;
bal=0;
bal+dep;
}
void bank::with()
{
cout<<"Amt to withdraw::";
cin>>amt;
if(amt>bal)
cout<<"Insufficient balance";
else
bal-=amt;
}
void bank::disp()
{
cout<<"Name::"<<name<<endl
<<"Balance::"<<bal<<endl;
}
void main()
{
clrscr();
bank b[10];
int ch,i,j;
for(i=1;i<=2;i++)
{
b[i].init();
}
while(1)
{
cout<<"1 to deposit"<<endl
<<"2 to withdraw"<<endl
<<"3 to deposit"<<endl
<<"4 to Exit::";
cin>>ch;
if(ch==1||ch==2||ch==3)
{
cout<<endl<<"Which customer details do you want to enter or view::";
cin>>j;
}
else
exit(1);
getch();
switch(ch)
{
case 1:
b[j].depo();
break;
case 2:
b[j].with();
break;
case 3:
b[j].disp();
break;
case 4:
exit(1);
}
getch();
}
}
FUNCTIONS_3
WAP TO PRINT THE LARGEST OF THE 2 NUMBERS USING (?:) CONDITIONAL OPERATOR
#include<iostream.h>
#include<conio.h>
class comparison
{
int x,y,max;
public:
void get();
void largest();
void print();
};
void comparison::get()
{
cout<<"Enter value of x & y::";
cin>>x>>y;
}
void comparison::largest()
{
max=(x>y)?x:y;
}
void comparison::print()
{
cout<<"x="<<x<<endl<<"y="<<y<<endl
<<"max="<<max ;
}
void main()
{
clrscr();
comparison c;
c.get();
c.largest();
c.print();
getch();
}
#include<iostream.h>
#include<conio.h>
class comparison
{
int x,y,max;
public:
void get();
void largest();
void print();
};
void comparison::get()
{
cout<<"Enter value of x & y::";
cin>>x>>y;
}
void comparison::largest()
{
max=(x>y)?x:y;
}
void comparison::print()
{
cout<<"x="<<x<<endl<<"y="<<y<<endl
<<"max="<<max ;
}
void main()
{
clrscr();
comparison c;
c.get();
c.largest();
c.print();
getch();
}
FUNCTIONS_2
WAP TO ENTER NUMBER OF STUDENTS AS PER USER CHOICE AND INPUT MARKS IN SUBJECTS AND DISPLAY
#include<iostream.h>
#include<conio.h>
class student
{
int rno;
char name[30];
float eng,math,sci,tot;
public:
void init();
void caltot();
void display();
};
void student::init()
{
cout<<"Enter rno,name,eng,math & science marks::";
cin>>rno>>name>>eng>>math>>sci;
}
void student::caltot()
{
tot=sci+math+eng;
}
void student::display()
{
cout<<"Rno::"<<rno<<endl
<<"Name::"<<name<<endl
<<"Science::"<<sci<<endl
<<"Math::"<<math<<endl
<<"English::"<<eng<<endl
<<"total::"<<tot<<endl;
}
void main()
{
clrscr();
int i,n;
cin>>n;
student s[4];
for(i=0;i<n;i++)
{
s[i].init();
s[i].caltot();
s[i].display();
}
getch();
}
#include<iostream.h>
#include<conio.h>
class student
{
int rno;
char name[30];
float eng,math,sci,tot;
public:
void init();
void caltot();
void display();
};
void student::init()
{
cout<<"Enter rno,name,eng,math & science marks::";
cin>>rno>>name>>eng>>math>>sci;
}
void student::caltot()
{
tot=sci+math+eng;
}
void student::display()
{
cout<<"Rno::"<<rno<<endl
<<"Name::"<<name<<endl
<<"Science::"<<sci<<endl
<<"Math::"<<math<<endl
<<"English::"<<eng<<endl
<<"total::"<<tot<<endl;
}
void main()
{
clrscr();
int i,n;
cin>>n;
student s[4];
for(i=0;i<n;i++)
{
s[i].init();
s[i].caltot();
s[i].display();
}
getch();
}
FUNCTIONS_1
WAP TO ENTER MARKS IN EACH SUBJECTS AND CALCULATE & DISPLAY THE TOTAL MARKS USING FUNCTION
#include<iostream.h>
#include<conio.h>
class student
{
int rno;
char name[30];
float eng,math,sci,tot;
public:
void init();
void caltot();
void display();
};
void student::init()
{
cout<<"Enter rno,name,eng,math & science marks::";
cin>>rno>>name>>eng>>math>>sci;
}
void student::caltot()
{
tot=sci+math+eng;
}
void student::display()
{
cout<<"Rno::"<<rno<<endl
<<"Name::"<<name<<endl
<<"Science::"<<sci<<endl
<<"Math::"<<math<<endl
<<"English::"<<eng<<endl
<<"total::"<<tot<<endl;
}
void main()
{
clrscr();
student s1,s2;
cout<<"Enter student 1 details::"<<endl;
s1.init();
s1.caltot();
s1.display();
cout<<"Enter student 2 details::"<<endl;
s2.init();
s2.caltot();
s2.display();
getch();
}
#include<iostream.h>
#include<conio.h>
class student
{
int rno;
char name[30];
float eng,math,sci,tot;
public:
void init();
void caltot();
void display();
};
void student::init()
{
cout<<"Enter rno,name,eng,math & science marks::";
cin>>rno>>name>>eng>>math>>sci;
}
void student::caltot()
{
tot=sci+math+eng;
}
void student::display()
{
cout<<"Rno::"<<rno<<endl
<<"Name::"<<name<<endl
<<"Science::"<<sci<<endl
<<"Math::"<<math<<endl
<<"English::"<<eng<<endl
<<"total::"<<tot<<endl;
}
void main()
{
clrscr();
student s1,s2;
cout<<"Enter student 1 details::"<<endl;
s1.init();
s1.caltot();
s1.display();
cout<<"Enter student 2 details::"<<endl;
s2.init();
s2.caltot();
s2.display();
getch();
}
4.Programming in C++ with output
WAP TO ENTER A STRING AND CHANGE ITS CASE USING FUNCTIONS
#include<conio.h>
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
void convert(char[40]);
void main()
{
clrscr();
char ch[40];
cout<<"Enter a string::";
gets(ch);
convert(ch);
getch();
}
void convert(char x[40])
{
int i;
for(i=0;i<strlen(x);i++)
{
if(islower(x[i]))
x[i]=toupper(x[i]);
else
x[i]=tolower(x[i]);
}
puts(x);
}
#include<conio.h>
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
void convert(char[40]);
void main()
{
clrscr();
char ch[40];
cout<<"Enter a string::";
gets(ch);
convert(ch);
getch();
}
void convert(char x[40])
{
int i;
for(i=0;i<strlen(x);i++)
{
if(islower(x[i]))
x[i]=toupper(x[i]);
else
x[i]=tolower(x[i]);
}
puts(x);
}
3.Programming in C++ with output
WAP TO ENTER 2 NUMBERS AND ADD,SUB,MULT OR DIVIDE THEM AS PER USER CHOICE
ALSO USER HAS TO ENTER THE DESIRE CHARACTER REPRESENTING THE CALCULATION
for e.g, see the output
#include<conio.h>#include<iostream.h>
void main()
{
clrscr();
char op;
float a,b,c;
cout<<"Enter 2 numbers::";
cin>>a>>b;
cout<<"Enter + to add"<<endl
<<"- to subtract"<<endl
<<"* to multiply"<<endl
<<"/ to divide::";
cin>>op;
switch(op)
{
case '+':
c=a+b;
break;
case '-':
c=a-b;
break;
case '*':
c=a*b;
break;
case '/':
c=a/b;
break;
}
cout<<"Result::"<<c;
getch();
}
2.Programming in C++ with output
//WAP TO CALCULATE AREA & VOLUME USING FUNCTION
#include<conio.h>
#include<iostream.h>
int sa(int,int,int);
int vol(int,int,int);
void main()
{
clrscr();
int l,b,h;
cout<<"Enter length,breadth & height::";
cin>>l>>b>>h;
cout<<"Surface Area::"<<sa(l,b,h)<<endl;
cout<<"Volume::"<<vol(l,b,h);
getch();
}
int sa(int x,int y,int z)
{
int sar=2*(x*y+x*z+y*z);
return(sar);
}
int vol(int x,int y,int z)
{
int vols=x*y*z;
return(vols);
}
Programming in C++ with output
W.A.P TO INPUT 3 SIDES OF A TRIANGLE PRINT INVALID DATA IF SUM OF 2 SIDES IS GREATER THAN THE THIRD SITE ELSE PRINT VALID DATA AND CALCULATES ITS AREA
#include<conio.h>
#include<iostream.h>#include<math.h>
void main()
{
clrscr();
int x,y,z;
cout<<"Enter x,y & z::";
cin>>x>>y>>z;
if(x>=y+z||y>=x+z||z>=x+y)
cout<<"Invalid data";
else
{
float s,q;
s=(x+y+z)/2;
q=s*(s-x)*(s-y)*(s-z);
cout<<"Area is::"<<sqrt(q);
}
getch();
}
Subscribe to:
Posts (Atom)







