Академический Документы
Профессиональный Документы
Культура Документы
Page 1 of 10
http://cbsecsnip.in
cin>>Agg;
GradeMe();
}
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();
}
3. Write a class to represent a vector (1-D numeric array). Include member functions:
for vector creation
for modification of a given element
for displaying the largest value in the vector.
for displaying the entire vector
Write a program using this class.
Ans. #include<iostream.h>
#include<conio.h>
#include<stdio.h>
int const size=50;
class vector
{
float d[size];
int s;
public:
void create(void);
void modify(void);
void largest(void);
void display(void);
};
Page 2 of 10
http://cbsecsnip.in
cout<<"Enter Value with which you want to Replace:-";
cin>>with;
d[mfy_value]=with;
}
void main()
{
clrscr();
vector o1;
int choice;
do
{
cout<<"\n\nChoice List\n";
cout<<"1) To Create Vector Array\n";
cout<<"2) To Modify Array\n";
cout<<"3) To find largest value\n";
cout<<"4) To Display\n";
cout<<"5) EXIT\n";
cout<<"Enter your choice:-";
cin>>choice;
switch(choice)
{
case 1: o1.create();
break;
case 2: o1.modify();
break;
case 3: o1.largest();
break;
case 4: o1.display();
break;
case 5: goto end;
}
Page 3 of 10
http://cbsecsnip.in
}while(1);
end:
getch();
}
4. 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;
Page 4 of 10
http://cbsecsnip.in
Member functions
To assign initial values (assign 0 to both data members)
To increment only people total in case ticket is not sold out
To increment people total as well as amount total if a ticket is sold out
To display the two totals
To display the number of tickets sold out (a ticky one)
Include a program to test this class.
Ans. #include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class ticbooth
{
int PeopleVisted;
float TotalAmount;
public:
ticbooth()
{
PeopleVisted = 0;
TotalAmount = 0.0;
}
void IncrementPeopleCounter()
{
PeopleVisted++;
cout<<endl<<"After increment total people: "<<PeopleVisted;
}
void Incre_people_amount()
{
TotalAmount=PeopleVisted*2.50;
cout<<endl<<"After increment total amount: "<<TotalAmount;
}
void ShowDetails()
{
cout << "People Visited : " << PeopleVisted;
cout<< "\nAmount Collected : " << TotalAmount ;
}
int TotalTicketsSold()
{
int TicketCount = (int)TotalAmount /2.5 ;
cout << "\n Total Tickets Sold : " << TicketCount ;
return TicketCount;
}
};
int main()
{
clrscr();
char ch;
int choice;
ticbooth t1;
l1:cout<<"\n\n\n\n1.Increment only person total or person and
amount both"<<endl;
cout<<"2.Display no. of people and the amount collected till
now"<<endl;
cout<<"3.Display no. of tickets sold"<<endl;
cout<<"4.Exit"<<endl;
Page 5 of 10
http://cbsecsnip.in
cout<<"Enter your choice:";
cin>>choice;
switch(choice)
{
case 1: cout<<"is ticket sold?(Y/N):";
cin>>ch;
if(ch=='N')
{
t1.IncrementPeopleCounter();
}
else
{
t1.IncrementPeopleCounter();
t1.Incre_people_amount();
}
goto l1;
break;
case 2: t1.ShowDetails();
goto l1;
break;
case 3: t1.TotalTicketsSold();
goto l1;
break;
case 4: exit(0);
break;
}
return 0;
getch();
}
6. 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
Ans. #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;
}
Page 6 of 10
http://cbsecsnip.in
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;
Page 7 of 10
http://cbsecsnip.in
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. 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:
Function Read_Data() to read an object of ADMISSION type.
Function Display() to display the details of an object.
Function Draw-Nos() to choose 2 students randomly.
And display the details. Use random function to generate admission nos. to match with AD_NO.
Ans. #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()
Page 8 of 10
http://cbsecsnip.in
{
cout<<"Enter Admission No (10 - 2000): ";
cin>>AD_NO;
cout<<"Name: ";
gets(NAME);
cout<<"Class: ";
gets(CLASS);
cout<<"Fees: ";
cin>>FEES;
}
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();
}
8. 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 Read_Data() to read an object of HOUSING type.
Function Display() to display the details of an object.
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.
Ans. #include<iostream.h>
#include<conio.h>
Page 9 of 10
http://cbsecsnip.in
#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
Page 10 of 10
http://cbsecsnip.in