Beruflich Dokumente
Kultur Dokumente
A member function GradeMe() to find the Grade as per the Aggregate Marks obtained by a student.
Equivalent Aggregate Marks range and the respective Grades are shown as follows:
Aggregate Marks
Grade
>=80
A
less than 80 and >=65
B
less than 65 ad >=50
C
less than 50
D
Public Members:
A function ENTER() to allow user to enter values for Ao, Name, Agg and call function GradeMe() to find the
Grade.
A fuction RESULT() to allow user to view the content of all the data members.
Ans. #include<iostream.h>
#include<conio.h>
#include<stdio.h>
class Applicant
{
long ANO;
char NAME[25];
float Agg;
char Grade;
void GradeMe()
{
if(Agg>=80)
Grade='A';
else if(Agg>=65)
Grade='B';
else if(Agg>=50)
Grade='C';
else if(Agg>=33)
Grade='D';
else
Grade='E';
}
public:
void ENTER()
{
cout<<"Enter Admission No:";
cin>>ANO;
cout<<"Enter Name of the Applicant :";
gets(NAME);
cout<<"Enter Aggregare Marks obtained by the Candidate :";
http://cbsecsnip.in
Page 1 of 10
cin>>Agg;
GradeMe();
3.
Ans.
}
void RESULT()
{
cout<<"*******Applicat Details***********"<<endl;
cout<<"Admission No: "<<ANO<<endl;
cout<<"Name of the Applicant: "<<NAME<<endl;
cout<<"Admission NoAggregare Marks obtained by the Candidate:
"<<Agg<<endl;
cout<<"Grade Obtained: "<<Grade<<endl;
}
};
void main(){
clrscr();
Applicant a1;
a1.ENTER();
a1.RESULT();
getch();
}
Write a class to represent a vector (1-D numeric array). Include member functions:
http://cbsecsnip.in
Page 2 of 10
http://cbsecsnip.in
Page 3 of 10
}while(1);
end:
getch();
}
Write a C++ program to implement a circle class. Each object of this class will represent a circle, storing its radius
and the x and y coordinate of its center as floats. Iclude two access functions for:
i.
calculating area of circle.
i.
calculating the circumference of circle.
Ans. #include<iostream.h>
#include<conio.h>
#include<stdio.h>
#define pi=3.14;
class circle
{
public:
float x,y,area,cir;
4.
5.
};
void main()
{
clrscr();
circle a1;
float x,y,radius;
cout<<"Enter x-cordinate : ";
cin>>x;
cout<<"Enter y-cordinate : ";
cin>>y;
cout<<"Enter radius : ";
cin>>radius;
cout<<endl<<"****************************"<<endl;
cout<<endl<<"x-cordinate is: "<<x;
cout<<endl<<"y-cordinate is: "<<y;
cout<<endl<<"Radius is: "<<radius;
a1.calarea(radius);
a1.calcir(radius);
getch();
}
Imagine a ticket selling booth at a fair. People passing by are requested to purchase a ticket. A ticket is priced as Rs.
2.50/-. The booth keeps track of the number of people that have visited the booth, and of the total amount of
money collected.
Model this ticket selling booth with a class called ticbooth including following members:
Data Members:
http://cbsecsnip.in
Page 4 of 10
Ans.
Member functions
http://cbsecsnip.in
Page 5 of 10
Ans.
}
Write a C++ program to perform various operations on a string class without using language supported built-in
string functions. The operations on a class are:
a)
Read a string
b)
Display the string
c)
Reverse the string
d)
Copy the string into an empty string
e)
Concatenate two strings
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
class string
{
char str1[20];
char str2[20];
public:
void read()
{
cout<<"\nEnter string :=> ";
cin>>str1;
}
void Display()
{
cout<<endl<<"The entered string is: "<<str1;
}
http://cbsecsnip.in
Page 6 of 10
void reverse();
void copy();
void concatenate();
};
void string::reverse()
{
int i,l,j=0;
cout<<"\nEnter string :=> ";
cin>>str1;
l=strlen(str1);
for(i=l-1;i>=0;i--)
{
str2[j]=str1[i];
j++;
}
str2[j]='\0';
cout<<"Reverse is: "<<str2;
}
void string::copy()
{
int i;
cout<<"\nEnter string :=> ";
cin>>str1;
for(i=0;i<=strlen(str1);i++)
{
str2[i]=str1[i];
}
str2[i]='\0';
cout<<"Copy is: "<<str2;
}
void string::concatenate()
{
int i,l;
cout<<"\nEnter string1 :=> ";
cin>>str1;
cout<<"\nEnter string2 :=> ";
cin>>str2;
l=strlen(str1);
for(i=0;i<=l;i++)
{
str1[l+i]=str2[i];
}
cout<<"Copy is: "<<str1;
}
int main()
{
clrscr();
int choice;
string s1;
l1:cout<<"\n\n\n\n1.Read the string"<<endl;
cout<<"2.Display the string "<<endl;
cout<<"3.Reverse the string"<<endl;
cout<<"4.Copy the string"<<endl;
cout<<"5.Concatenate two strings"<<endl;
http://cbsecsnip.in
Page 7 of 10
cout<<"6.Exit"<<endl;
cout<<"Enter your choice:";
cin>>choice;
switch(choice)
{
case 1:
s1.read();
goto l1;
break;
case 2:
s1.Display();
goto l1;
break;
case 3:
s1.reverse();
goto l1;
break;
case 4:
s1.copy();
goto l1;
break;
case 5:
s1.concatenate();
goto l1;
break;
case 6:
exit(0);
break;
}
return 0;
getch();
7.
Ans.
}
Define a class named ADMISSION in C++ with the following description:
Private Members:
AD_NO
integer (Ranges 10 - 2000)
NAME
Array of characters (String)
CLASS
Character
FEES
Float
Public Members:
And display the details. Use random function to generate admission nos. to match with AD_NO.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
class ADMISSION
{
private:
int AD_NO;
char NAME[50];
char CLASS[5];
float FEES;
public:
void Read_Data();
void Display();
void Draw_Nos();
};
void ADMISSION::Read_Data()
http://cbsecsnip.in
Page 8 of 10
{
cout<<"Enter Admission No (10 - 2000): ";
cin>>AD_NO;
cout<<"Name: ";
gets(NAME);
cout<<"Class: ";
gets(CLASS);
cout<<"Fees: ";
cin>>FEES;
8.
Ans.
}
void ADMISSION::Display()
{
cout<<"Admission No:"<<AD_NO<<endl;
cout<<"Name: "<<NAME<<endl;
cout<<"Class: "<<CLASS<<endl;
cout<<"Fees: "<<FEES<<endl;
}
void ADMISSION::Draw_Nos()
{
int Arr[5];
int no1,no2,i;
randomize();
no1=random(1991)+10;
//Generate a radom no between 10-2000
no2=random(1991)+10;
//Generate a radom no between 10-2000
cout<<"Random no-1: "<<no1<<" Random no-2: "<<no2;
for(i=0;i<100;i++)
{
if((Arr[i]==no1)||(Arr[i]==no2))
Display();
}
}
void main()
{
clrscr();
ADMISSION a1;
a1.Read_Data();
a1.Display();
a1.Draw_Nos();
getch();
}
Define a class named HOUSING in C++ with the following description:
Private Members:
REG_NO
integer (Ranges 10 - 2000)
NAME
Array of characters (String)
TYPE
Character
COST
Float
Public Members:
Function Draw-Nos() to choose and display the details of 2 houses selected randomly from an array of 10
objects of type HOUSING. Use random function to generate the registration nos. to match with REG_NO from the
array.
#include<iostream.h>
#include<conio.h>
http://cbsecsnip.in
Page 9 of 10
#include<stdio.h>
#include<stdlib.h>
class HOUSING{
private:
int REG_NO;
char NAME[50];
char TYPE[20];
float COST;
public:
void Read_Data();
void Display();
void Draw_Nos();
};
void HOUSING::Read_Data()
{
cout<<"Enter Reg No (10 - 1000): ";
cin>>REG_NO;
cout<<"Name: ";
gets(NAME);
cout<<"Type: ";
gets(TYPE);
cout<<"Cost: ";
cin>>COST;
}
void HOUSING::Display()
{
cout<<"Reg No:"<<REG_NO<<endl;
cout<<"Name: "<<NAME<<endl;
cout<<"Type: "<<TYPE<<endl;
cout<<"Cost: "<<COST<<endl;
}
void HOUSING::Draw_Nos()
{
int Arr[5];
int no1,no2,i;
randomize();
no1=random(991)+10;
//Generate a radom no between 10-1000
no2=random(991)+10;
//Generate a radom no between 10-1000
cout<<"Random no-1: "<<no1<<" Random no-2: "<<no2;
for(i=0;i<100;i++)
{
if((Arr[i]==no1)||(Arr[i]==no2))
Display();
}
}
void main(){
clrscr();
HOUSING a1;
a1.Read_Data();
a1.Display();
a1.Draw_Nos();
getch();
}
SHORT QUESTION ANSWERS
http://cbsecsnip.in
Page 10 of 10