Skip to main content

CLASS and OBJECTS

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( );} 
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.
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.
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. 
5. Define a class TAXPAYER in C++ with following description :                             For - 4 Marks
Private members :
  1. Name  of type string
  2. PanNo of type string
  3. Taxabincm (Taxable income) of type float
  4. TotTax of type double
  5. 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 :
    • 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.
6. Find the output of the following C++ program:

#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:
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

Popular posts from this blog

function solution

1. // to find areas using functions.using switch import java.io.*; class m1 { double area(double r) {   return(3.14*r*r); } int area(int s) {   return(s*s); } double area(double l, double b) {   return(l*b); } public static void main(String args[]) throws IOException {   m1 ob= new m1(); double p; int q; double w; BufferedReader input= new BufferedReader(new InputStreamReader(System.in)); System.out.println("*** MAIN MENU ***"); System.out.println("1. Area of Circle"); System.out.println("2. Area of Square"); System.out.println("3. Area of Rectangle"); System.out.println("4. Exit"); System.out.println("Enter Choice(1-4)"); int ch=Integer.parseInt(input.readLine()); switch(ch) { case 1: System.out.println("Enter the radius"); double r=Double.parseDouble(input.readLine()); p=ob.area(r); System.out.println("Area of Circle"+p); brea...
CYBER OLYMPIAD SYLLABUS Cyber Olmpiad CLASS-2 Total Questions : 35   Time : 1 hr. Syllabus Section – 1 : Patterns, Measuring Units, Odd One Out, Series Completion,  Geometrical Shapes, Analogy, Ranking Test, Grouping of Figures, Coding-Decoding, Embedded Figures. Section – 2 : Introduction to Computers, General Information about Computers, Parts of Computer, Uses of Computer, Learning to use Keyboard and Mouse, Introduction to MS-Paint, Latest Developments in the field of IT. Section – 3 : Higher Order Thinking Questions - Syllabus as per Section – 2.          Questions are based on Windows 7 and MS-Office 2010. CLASS-3 Total Questions : 35   Time : 1 hr. Syllabus Section – 1 : Patterns, Analogy and Classification, Coding-Decoding, Mirror Images, Embedded Figures, Alphabet Test, Ranking Test, Grouping of Figures, Figure Matrix, Geometrical Shapes, Days and Dates & Possible Combinations. Section – 2...