CLASS and OBJECTS
1.Give the output of the following program ( Assuming that all required header files are included in the program ) :
class TEMP
{ static int a;
float b;
public:
TEMP( )
{ b=10; }
void INTEMP( )
{ a++;
b=a+10; }
void OUTTEMP( )
{ cout<<a*i<<"$"<<b-3<<endl; } };
int TEMP::a=2;
void main()
{ TEMP ob[5];
for(int x=1;x<5;x++)
ob[x].INTEMP( );
for(x=1;x<5;x++)
ob[x].OUTTEMP( );}
{ static int a;
float b;
public:
TEMP( )
{ b=10; }
void INTEMP( )
{ a++;
b=a+10; }
void OUTTEMP( )
{ cout<<a*i<<"$"<<b-3<<endl; } };
int TEMP::a=2;
void main()
{ TEMP ob[5];
for(int x=1;x<5;x++)
ob[x].INTEMP( );
for(x=1;x<5;x++)
ob[x].OUTTEMP( );}
2. Define a class Travel in C++ with the description given below:
Private Members:
T_Code of type string
No_of_Adults of type integer
No_of_Children of type integer
Distance of type integer
TotalFare of type float
Public Members:
A constructor to assign initial values as follows :
T_Code with the word “NULL”
No_of_Adults as 0
No_of_Children as 0
Distance as 0
TotalFare as 0
A function AssignFare( ) which calculates and assigns the value
of the data member TotalFare as follows :
For each Adult
Fare (Rs) For Distance (Km)
500 >=1000
300 <1000 & >=500
200 <500
For each Child the above Fare will be 50% of the Fare mentioned in the above table.
For example :
If Distance is 750, No_of_Adults = 3 and No_of_Children = 2
Then TotalFare should be calculated as
No_of_Adults * 300 + No_of_Children * 150
i.e. 3 * 300 + 2 * 150 = 1200
• A function EnterTraveK ) to input the values of the data members
T_Code, No_of_Adults, No_of_Children and Distance; and invoke the AssignFare( )
function.
• A function ShowTraveK) which displays the content of all the data members for a
Travel.
Private Members:
T_Code of type string
No_of_Adults of type integer
No_of_Children of type integer
Distance of type integer
TotalFare of type float
Public Members:
A constructor to assign initial values as follows :
T_Code with the word “NULL”
No_of_Adults as 0
No_of_Children as 0
Distance as 0
TotalFare as 0
A function AssignFare( ) which calculates and assigns the value
of the data member TotalFare as follows :
For each Adult
Fare (Rs) For Distance (Km)
500 >=1000
300 <1000 & >=500
200 <500
For each Child the above Fare will be 50% of the Fare mentioned in the above table.
For example :
If Distance is 750, No_of_Adults = 3 and No_of_Children = 2
Then TotalFare should be calculated as
No_of_Adults * 300 + No_of_Children * 150
i.e. 3 * 300 + 2 * 150 = 1200
• A function EnterTraveK ) to input the values of the data members
T_Code, No_of_Adults, No_of_Children and Distance; and invoke the AssignFare( )
function.
• A function ShowTraveK) which displays the content of all the data members for a
Travel.
3. Define a class TEST in C++ with following description:
Private Members
• TestCode of type integer
• Description of type string
• NoCandidate of type integer
• CenterReqd (number of centers required) of type integer
• A member function CALCNTR() to calculate and return the number of centers as
(NoCandidates/100+1)
Public Members
• A function SCHEDULE() to allow user to enter values for TestCode, Description,
NoCandidate & call function CALCNTR() to calculate the number of Centres
• A function DISPTEST() to allow user to view the content of all the data members.
Private Members
• TestCode of type integer
• Description of type string
• NoCandidate of type integer
• CenterReqd (number of centers required) of type integer
• A member function CALCNTR() to calculate and return the number of centers as
(NoCandidates/100+1)
Public Members
• A function SCHEDULE() to allow user to enter values for TestCode, Description,
NoCandidate & call function CALCNTR() to calculate the number of Centres
• A function DISPTEST() to allow user to view the content of all the data members.
4. Define a class Clothing in C++ with the following descriptions:
Private Members:
Code of type string
Type of type string
Size of type integer
Material of type string
Price of type float
A function Calc_Price() which calculates and assigns the value of Price as
follows:
For the value of Material as “COTTON”
Type Price (Rs.)
TROUSER 1500
SHIRT 1200
For Material other than “COTTON” the above mentioned Price gets reduced by 25%.
Public Members:
A constructor to assign initial values of Code, Type and Material with the word “NOT ASSIGNED” and Size and Price with 0. A function Enter () to input the values of the data members Code, Type,
Size and Material and invoke the CalcPrice() function. A function Show () which displays the content of all the data members for a Clothing.
Private Members:
Code of type string
Type of type string
Size of type integer
Material of type string
Price of type float
A function Calc_Price() which calculates and assigns the value of Price as
follows:
For the value of Material as “COTTON”
Type Price (Rs.)
TROUSER 1500
SHIRT 1200
For Material other than “COTTON” the above mentioned Price gets reduced by 25%.
Public Members:
A constructor to assign initial values of Code, Type and Material with the word “NOT ASSIGNED” and Size and Price with 0. A function Enter () to input the values of the data members Code, Type,
Size and Material and invoke the CalcPrice() function. A function Show () which displays the content of all the data members for a Clothing.
5. Define a class TAXPAYER in C++ with following description : For - 4 Marks
Private members :
Private members :
- Name of type string
- PanNo of type string
- Taxabincm (Taxable income) of type float
- TotTax of type double
- A function CompTax( ) to calculate tax according to the following slab:
Taxable Income Tax%
Up to 160000 0
>160000 and <=300000 5
>300000 and <=500000 10
>500000 15
Public members :
Up to 160000 0
>160000 and <=300000 5
>300000 and <=500000 10
>500000 15
Public members :
- A parameterized constructor to initialize all the members
- A function INTAX( ) to enter data for the tax payer and call function CompTax( ) to assign TotTax.
- A function OUTAX( ) to allow user to view the content of all the data members.
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
class Class
{
int Cno,total;
char section;
public
:
Class(int no=1)
{
Cno=no;
section='A';
total=30;
}
void addmission(int c=20)
{
section++;
total+=c;
}
void ClassShow()
{
cout<<Cno<<":"<<section<<":"<<total<<endl;
}
} ;
void main()
{
Class C1(5),C2;
C1.addmission(25);
C1.ClassShow();
C2.addmission();
C1.addmission(30);
C2.ClassShow();
C1.ClassShow();
}
7. Define a class ITEM in C++ with following description:
7. Define a class ITEM in C++ with following description:
Private members:
Icode of type integer (Item Code)
Item of type string (Item Name)
Price of type Float (Price of each item)
Qty of type integer (Quantity in stock)
Discount of type float (Discount percentage on the item)
A find function finddisc( ) to calculate discount as per the following rule:
If Qty <=50
disco
unt is 0%
If 50 < Qty <=100
discount is 5%
If Qty>100
discount is 10%
Public members :
A function Buy( ) to allow user to enter values for Icode, Item,Price, Qty and call function
Finddisc ( ) to calculate the discount. A function showall ( ) to allow user to view t he content of all the data members.
Comments
Post a Comment