5: To Calculate Charge of A Resort
5: To Calculate Charge of A Resort
#include<iostream.h>
#include<conio.h>
class resort
{ int rno;
char name[20];
int charges;
int days;
int amount;
void compute()
{ amount=days*charges;
if(amount>20000)
amount=amount*1.5;
}
public:
void read();
void display();
};
void resort::read()
{ cout<<"Enter room no. & name of the coustmer:"<<" ";
cin>>rno;
cout<<" ";
cin>>name;
cout<<"Enter no. of days & charges per day:";
cin>>days;
cout<<" ";
cin>>charges;
compute();
}
void resort::display()
{
cout<<"Name & room no. of the coustmer is:"<<" ";
cout<<name<<" "<<rno<<endl;
cout<<"No. of days coustmer stayed and charges each days are:"<<" ";
cout<<days<<"&"<<charges<<"Rs. per day"<<endl;
cout<<"Amoumnt coustmer have to be payed:"<<amount;
}
void main()
{ resort rs;
clrscr();
rs.read();
rs.display();
getch();
}
}
cout<<"Do you want to continue:";
cin>>choice;
}while(choice=='y');
getch();
}
PROGRAM-4
TO MAKE THE CLASS STUDENT WHICH CONTAIN THE DATA
ABOUT STUDENT.
#include<iostream.h>
#include<math.h>
#include<conio.h>
class student
{int rno ,s;
int avg;
char name[30],grade;
int marks[5];
void calcgrade();
public:
void read();
void display();
};
void student::calcgrade()
{ if(avg>=90)
grade='A';
else if(avg>=80)
grade='B';
else if(avg>=70)
grade='C';
else
grade='F';
}
void student::read()
{cout<<"enter rno";
cin>>rno;
cout<<"name";
cin>>name;
s=0;
for(int i=0;i<5;i++)
{ cout<<"marks";
cin>>marks[i];
s+=marks[i];
}
avg=s/5;
calcgrade();
}
void student::display()
{cout<<rno<<"\n";
cout<<name<<"\n";
cout<<avg<<"\n";
cout<<grade<<"\n";
}
void main()
{ clrscr();
student s;
s.read();
s.display();
getch();
}
PROGRAM-8
TO FIND THE LARGEST ELEMENT FROM ARRAY.
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a[15],i,largest,pos;
for(i=0;i<15;i++)
{
cout<<"enter array element"<<i+1<<"\n";
cin>>a[i]; }
largest=a[0];
for(i=1;i<15;i++)
{if(a[i]>largest)
{largest=a[i];
pos=i; }
cout<<"the largest element"<<pos+1<<"\n";
cout<<largest<<"\n";
}
getch();
}
Program11
Using an array with pointer
#include<iostream.h>
#include<conio.h>
void main()
{ int A[5]; clrscr();
int *ptr=A;
for(int i=0;i<4;i++)
{ cin>>A[i];
for(i=1;i<3;i++)
{ cout<<*ptr<<"#";
ptr++;
cout<<endl;
for(i=1;i<4;i++)
{ (*ptr)*=3;
--ptr;
for(i=1;i<5;i++)
cout<<A[i-1]<<"@";
cout<<endl;
getch();