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

Arid Agriculture University, Rawalpindi: Mid Exam Spring 2021 (Paper Duration 12 Hours) To Be Filled by Teacher

The document contains details about a midterm exam for an Object Oriented Programming course at Arid Agriculture University in Rawalpindi, Pakistan. It includes the course number and title, date of the exam, total marks, and spaces for the teacher and student to fill in details like the student's name, registration number, answers to questions, and marks obtained. It also contains sample code for two C++ programming questions asked in the exam related to defining class methods and calculating details for an employee class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views

Arid Agriculture University, Rawalpindi: Mid Exam Spring 2021 (Paper Duration 12 Hours) To Be Filled by Teacher

The document contains details about a midterm exam for an Object Oriented Programming course at Arid Agriculture University in Rawalpindi, Pakistan. It includes the course number and title, date of the exam, total marks, and spaces for the teacher and student to fill in details like the student's name, registration number, answers to questions, and marks obtained. It also contains sample code for two C++ programming questions asked in the exam related to defining class methods and calculating details for an employee class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Pir Mehr Ali Shah

Arid Agriculture University, Rawalpindi


Office of the controller of Examinations
Mid Exam Spring 2021 (Paper Duration 12 hours)
To be filled by Teacher

Course No.: CS-423……………………………Course Title:……… Object Oriented Programming


Total Marks:……18…………………Date of Exam:…………26-04-2021……......................................
Degree: ………BS(IT)……… ……….Semester:………2nd ………………… Section:……(A/B) ………………
Marks
Q. No. 1 2 3 4 5 6 7 8 9 10 Obtained/
TotalMarks
Marks
Obtained
Total Marks in Words:
Name of the teacher: TAYYABA KALSOOM
Who taught the course: Signature of teacher / Examiner:

To be filled by Student

Registration No.: ……………20-ARID -4152………….……… Name:………Shaheryar Hashmi……………………..

Answer the following questions.


Question 1-Let’s assume we have a class ‘Arithmetic’ with two member functions Add() and
Subtract(). Suppose Add() function is defined within class then how will the subtract() function be
defined out of the class boundary. Explain it with the help of some suitable program.
Solution-
#include<iostream>
using namespace std;
class Arithmetic {
public:

int a,b,result;
void add();
voidsub ();
};
int main() {
Arithmetic obj;

void add();
cout << "Enter the first num :";
cin >> obj.a;
cout << "Enter the second num :";
cin >> obj.b;
obj.result = obj.a + obj.b;
cout << obj.a << " + " << obj.b <<" = " <<obj.result<< endl;
void sub();

cout << "Enter the first num :";


cin >> obj.a;
cout << "Enter the second num:";
cin >> obj.b;
obj.result = obj.a - obj.b;

cout << obj.a << " - " << obj.b <<" = " <<obj.result<< endl;

return 0;

Question 2-
Solution-
#include<iostream>
using namespace std;

class Employee
{
int eid;
char ename[100];
float basic_salary, hra, da, i_tax, net_salary;

public:
void accept_details()
{
cout<<"\n Enter Employee Id : ";
cin>>eid;
cout<<"\n Enter Employee Name : ";
cin>>ename;
cout<<"\n Enter Basic Salary : ";
cin>>basic_salary;

}
void display_details()
{
cout<<"\n ----------------------- ";
cout<<"\n Employee Id : "<<eid;
cout<<"\n Employee Name : "<<ename;
cout<<"\n Basic Salary : "<<basic_salary;
}
};
int main()
{
Employee e;
e.accept_details();
e.display_details();
return 0;
}

#include <iostream>
#include<conio.h>

using namespace std;

// Student Class Declaration


class StudentClass {
private://Access - Specifier
//Member Variable Declaration
char name[20];
int regNo, sub1, sub2, sub3;
float total, avg;

public://Access - Specifier
//Member Functions read() and print() Declaration

void read() {
//Get Input Values For Object Variables
cout << "Enter Name :";
cin >> name;

cout << "Enter Registration Number :";


cin >> regNo;

cout << "Enter Marks for Subject 1,2 and 3 :";


cin >> sub1 >> sub2>> sub3;
}

void sum() {
total = sub1 + sub2 + sub3;
avg = total / 3;
}

void print() {
//Show the Output
cout << "Name :" << name << endl;
cout << "Registration Number :" << regNo << endl;
cout << "Marks :" << sub1 << " , " << sub2 << " , " << sub3
<< endl;
cout << "Total :" << total << endl;
cout << "Average :" << avg << endl;
}
};

int main() {
// Object Creation For Class
StudentClass stu1, stu2;

cout << "Read and Print Student Information Class Example


Program In C++\n";

cout << "\nStudentClass : Student 1" << endl;


stu1.read();
stu1.sum();
stu1.print();

cout << "\nStudentClass : Student 2" << endl;


stu2.read();
stu2.sum();
stu2.print();

getch();
return 0;
}

You might also like