C++ Lab Worksheet 5.1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

EXPERIMENT NUMBER –Practical 5.1.

1
STUDENT’S NAME – Aryaman Sharma

STUDENT’S UID – 20BCS4206

CLASS AND GROUP – 20CC2 AND B

SEMESTER – 2

TOPIC OF EXPERIMENT –

LEARN HOW TO USE CLASSES USING C++

AIM OF THE EXPERIMENT –

Write a program that takes information about institute staff information for

1) Teacher code, name, subject and publication

2) Officer code, name and grade

3) Typist code, name, speed and daily wages and displays it using hierarchal
inheritance.

ALGORITHM –

 START

 Create a class staff.

 Initialize variables like code, name using protected access specifier.

 Create a member function getstaff() and print the details and accept the input

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
from the user by using public access specifier.

 Create a member function putstaff() and print the details .

 Create a class teacher defining the class staff .

 Initialize variables like sub,pub.

 Create a member function getdata() and print the details and accept the input

from the user by using public access specifier.

 Create a member function putdata() and print the details .

 Create a class officer defining the class staff.

 Initialize the variables grade.

 Create a member function void create()and print the details and accept the

input from the user by using public access specifier.

 Create a member function void display() and print the details .

 Create a class typist defining the class staff.

 Initialize the variables like speed,dw.

 Create a member function gettypist()and print the details and accept the input

from the user by using public access specifier.

 Create a member function disptypist() and print the details .

 Call all the functions in main using the dot(.) operator.

 Return an integer value.

 STOP.

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
PROGRAM CODE –

SUBJECT NAME- OBJECT ORIENTED PROGRAMMING


USING C++ LAB
SUBJECT CODE-CSP-152
ERRORS ENCOUNTERED DURING PROGRAM’S EXECUTION –

<-----No Error Occurred----->


PROGRAMS’ EXPLANATION (in brief) –

In this program we have to enter the information of institute staff by creating class
staff and by using public and protected specifiers and different member functions and
display it using hierarchical inheritance

OUTPUT –
EXPERIMENT NUMBER –Practical 5.1.2
STUDENT’S NAME – Aryaman Sharma

STUDENT’S UID – 20BCS4206

CLASS AND GROUP – 20CC2 AND B

SEMESTER – 2

TOPIC OF EXPERIMENT –

LEARN HOW TO USE CLASSES USING C++

AIM OF THE EXPERIMENT –

Create a class student having student uid and getnumber(),putnumber() as


member functions to get the values and display it. Derive a class test having marks
in different subjects and getmarks() and putmarks() as member functions to get
and display the values. Derive another class sports from student class having
sports score and getscore(), putscore() as member functions to get and display the
values. Derive a class result from test and sports class and define a function
display() to calculate total marks. Implement it with the object of result class. If it
gives any error, resolve it by adding the required functionality.

ALGORITHM –

 START

 Create a class student.

 Initialize a variable uid.

 Create a member function getnumber() and putnumber() to print the details


and accept the input from the user by using public access specifier.
 Create a class test by defining a virtual public class student.

 Initialize variables like part1 and part2.

 Create a member function getmarks() and putmarks() print the details and
accept the input from the user by using public access specifier.

 Create a class sports by defining a virtual public class student.

 Initialize a variable score.

 Create a member function getscore() and putscore() to print the details and
accept the input from the user by using public access specifier.

 Create a class result by defining class test and sports.

 Initialize a variable total.

 Create a member function display().

 Calculate total by using the formula:

 total=part1+part2+sports

 Implement all the member functions with the object of this class to print the
details.

 Call all the member functions in main function using dot(.) obj.

 Return an integer value.

 End.
PROGRAM CODE –
ERRORS ENCOUNTERED DURING PROGRAM’S EXECUTION –

<-----No Error Occurred----->

PROGRAMS’ EXPLANATION (in brief) –

In this program we have to create a class student having student uid and
getnumber(),putnumber() as member functions to get the values and display it and
then derive a class test having marks in different subjects and getmarks() and
putmarks() as member functions to get and display the values. After that derive
another class sports from student class having sports score and getscore(),
putscore() as member functions to get and display the values. And then derive a
class result from test and sports class and define a function display() to calculate
total marks. After that call all these member functions in main function and print
the details by using dot(.) operator.

OUTPUT –
EXPERIMENT NUMBER –Practical 5.1.2
STUDENT’S NAME – Aryaman Sharma

STUDENT’S UID – 20BCS4206

CLASS AND GROUP – 20CC2 AND B

SEMESTER – 2

TOPIC OF EXPERIMENT –

LEARN HOW TO USE CLASSES USING C++

AIM OF THE EXPERIMENT –

WAP to illustrate how the constructors are implemented and the order in which
they are called when the classes are inherited. Use three classes named alpha,
beta, gamma such that alpha, beta are base class and gamma is derived class
inheriting alpha &beta. Pass four variable to gamma class object which will further
send one integer variable to alpha(),one float type variable to beta().Show the
order of execution by invoking constructor of derived class.

ALGORITHM –

 START

 Create a class alpha.

 Initialize a variable x.
 Pass the values in class alpha and print the details.

 Create a member function show_x() and accept the input from user and print
the details.

 Create a class beta.

 Initialize the variable y.

 Pass the values in class beta and print the details.

 Create a member function show_y() and accept the input from user and print
the details.

 Create a class gamma by defining the class alpha and beta

 Initialize variable m,n.

 Pass the values in class gamma and print the details.

 Create a member function show_mn() and accept the input from user and print
the details.

 Call all the member functions in the main function using dot(.)g.

 Return an integer value.

 End.  
PROGRAM CODE –
ERRORS ENCOUNTERED DURING PROGRAM’S EXECUTION –

<-----No Error Occurred----->

PROGRAMS’ EXPLANATION (in brief) –

In this program we have to create three classes named alpha, beta, gamma such
that alpha, beta are base class and gamma is derived class inheriting alpha &beta.
Pass four variable to gamma class object which will further send one integer
variable to alpha(),one float type variable to beta().Show the order of execution by
invoking constructor of derived class.

OUTPUT –
LEARNING OUTCOMES
 Identify situations where computational methods would be useful.

 Approach the programming tasks using techniques learnt and write pseudo-code.

 Choose the right data representation formats based on the requirements of the problem.

 Use the comparisons and limitations of the various programming constructs and choose
the right one for the task.

EVALUATION COLUMN (To be filled by concerned faculty only)

Sr. No. Parameters Maximum Marks


Marks Obtained
1. Worksheet Completion including writing 10
learning objective/ Outcome
2. Post Lab Quiz Result 5

3. Student engagement in Simulation/ 5


Performance/ Pre Lab Questions
4. Total Marks 20

You might also like