0% found this document useful (0 votes)
25 views8 pages

5: To Calculate Charge of A Resort

The document contains code snippets demonstrating various C++ programming concepts: 1. A Resort class calculates charges based on number of days stayed and displays customer details and amount due. 2. Code shows string operations like concatenation, length calculation, and copying using functions like strcat, strlen, strcpy. 3. A Student class calculates grade based on average marks and displays student details like roll number, name, average, and grade. 4. Code finds largest element in an array and its position by iterating through array elements.

Uploaded by

Ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views8 pages

5: To Calculate Charge of A Resort

The document contains code snippets demonstrating various C++ programming concepts: 1. A Resort class calculates charges based on number of days stayed and displays customer details and amount due. 2. Code shows string operations like concatenation, length calculation, and copying using functions like strcat, strlen, strcpy. 3. A Student class calculates grade based on average marks and displays student details like roll number, name, average, and grade. 4. Code finds largest element in an array and its position by iterating through array elements.

Uploaded by

Ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

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();
}

7: Various Operations on Strings


#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
{ char a[50];
char b[50];
int ch;
clrscr();
char choice;
cout<<"Enter string 1:";
cin>>a;
cout<<"Enter string 2:";
cin>>b;
do{
cout<<"Menu:"<<endl<<"1.string concatenation."<<endl<<"2.string
lenth."<<endl<<"3.string copy."<<endl;
cout<<"Enter your choice(1,2,3):";
cin>>ch;
switch(ch)
{
case 1:strcat(a,b);
cout<<"String 1 becomes:"<<a<<endl;
cout<<"String 2 becomes:"<<b<<endl;
break;
case 2:int al=strlen(a);
int bl=strlen(b);
cout<<"Lenth of string 1 is:"<<al<<endl;
cout<<"Lenth of string 2 is:"<<bl<<endl;
break;
case 3:strcpy(a,b);
cout<<a;
cout<<b;
break;
default:
exit(0);

}
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;

cout<<"enter the element of array:";

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();

You might also like