0% found this document useful (0 votes)
60 views

Class C++

The document defines four C++ classes: 1) A Candidate class with data members for admission number, name, category, and fees, and member functions to input data, assign fees based on category, and output data. 2) A Ring class with private data members for ring number, radius, area and a function to calculate area, and public functions to input values and display them. 3) A Worker class with private data members for worker number, name, hours worked, wage rate and total wage, and public functions to input data, calculate total wage, and display data. 4) A Test class with private data members for test code, description, number of candidates, center required

Uploaded by

UNKNOWN
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)
60 views

Class C++

The document defines four C++ classes: 1) A Candidate class with data members for admission number, name, category, and fees, and member functions to input data, assign fees based on category, and output data. 2) A Ring class with private data members for ring number, radius, area and a function to calculate area, and public functions to input values and display them. 3) A Worker class with private data members for worker number, name, hours worked, wage rate and total wage, and public functions to input data, calculate total wage, and display data. 4) A Test class with private data members for test code, description, number of candidates, center required

Uploaded by

UNKNOWN
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/ 10

2.

Class and Object


QUES2.1) write a program to define a class candidate with the following
specification

DATA MEMBERS:

 Admission no.of type long int


 Name of type character aaray
 Category of type integer
 Fees of type float

MEMBER FUNCTION:

 A private member function AFEES() to assign fees depending on


category that is

If category is G then fees is rs 5000

If category is F then fees is 7500

If category is S or T then fees is rs 2500

 A public member function INPUT() to accept admission no. , name and


category and to call the function AFEES() to assign fees
 A public member function OUTPUT() to display all the contents .

Ans) #include<iostream.h>

#include<conio.h>

class candidate

longintano;

char name[20];

char category;
float fees;

void AFEES()

if(category==’G’)

fees=5000;

else if(category==’f’)

fees=7500;

else if(category==’S’||category==’T’)

fees=2500;

public:

void INPUT()

{
cout<<”enter admission no. and category”;

cin>>ano>>category;

cout<<”enter name”;

cin>>name;

AFEES();

void OUTPUT()

cout<<name<<endl<<ano<<endl;
cout<<category<<endl<<fees;

};

void main()

candidate c;

c.INPUT();

c.OUTPUT();

getch();

QUES2.2) write a program to define a class RING in C++ with following

PRIVATE MEMBERS:

 Ring number of type int


 Radius of type float
 Area of type float
 calcarea()

PUBLIC MEMBERS:

 getarea() to input all the values and to call calcarea() to calculate


 showarea() to display all the values
Ans) #include<iostream.h>

#include<conio.h>

class RING

intrno;

floatr,a;

voidcalcarea()

a=3.14*r*r;

public:

voidgetarea()

cout<<”enter ring number and radius”;

cin>>rno;

cin>>r;

calcarea();

voidshowarea()

cout<<rno<<endl<<r<<endl<<a<<endl;

}
};

void main()

RING ri;

ri.getarea();

ri.showarea();l

getch();

QUES2.3) write a program to define a class worker with following specifications

PRIVATE MEMBERS:

 wno (int)
 wname (20 character array)
 hrwrk,wgrate (float) ( hour work and wage rate)
 totwage (float; hrwrk*wgrate)
 calwg() ( a function to calculate the totwage with float return type)
PUBLIC MEMBERS:

 takedata() [function to read wno, wname,hrwrk and call calwg() to


calculate total wage]
 showdata() [to display all data members on screen]

Ans)#include<iostream.h>

#include<conio.h>

class worker

int wno;

char wname[20];

float hrwrk,wgrate,totwage,ans;

float calwg();

public:

void takedata();

void showdata();

};

float worker::calwg()

totwage=hrwrk*wgrate;

return(totwage);

void worker::takedata()

{
cout<<”enter name”;

cin>>wname;

cout<<”worker no., hour worked and wage rate”;

cin>>wno>>hrwrk>>wgrate;

ans=calwg();

void worker::showdata()

cout<<wname<<endl<<wno<<endl<<hrwrk<<endl<<wgrate<<endl<<ans<<endl;

void main()

worker w;

w.takedata();

w.showdata();

getch();

}
QUES2.4)write a program to define a class TEST IN C++ with the following
specification

PRIVATE MEMBERS:

 test code (int)


 description (20 character)
 no. of candidates (int)
 center required (int)
 calcntr() [to calculate no. of center required as creq=no/100 +1]

PUBLIC MEMBERS:

 a function schedule() to take input of all values


 a function dispdata() to display all the values

ans) #include<iostream.h>

#include<conio.h>

class TEST

inttcode;

chardesc[20];

intno,creq;

voidcalcntr();

public:

void schedule();

voiddispdata();

};

void TEST::calcntr()
{

creq=no/100 +1;

void TEST::schedule()

cout<<” enter test code &no. of candidates”;

cin>>tcode;

cin>>no;

cout<<” enter description”;

gets(desc);

calcntr();

void TEST::dispdata()

cout<<tcode<<endl<<no<<endl<<desc<<endl<<” center required:-“<<creq;

void main()

TEST t;

t.schedule();

t.dispdata();

getch();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy