0% found this document useful (0 votes)
36 views6 pages

OOP - Spring22 - FinalPaper Soln

Uploaded by

javeriaamirusc
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)
36 views6 pages

OOP - Spring22 - FinalPaper Soln

Uploaded by

javeriaamirusc
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/ 6

PMAS Arid Agriculture University Rawalpindi

University Institute of Information Technology


Final Term Paper (Spring-2022)
BSCS/BSIT/BSSE (Morning/Evening)
Object Oriented Programming (CS-423)
Maximum Marks: 30 (Theory) Total Time: 1:45 Hr
-------------------------------------------------------------------------------------------------------------------------------
Question #1: 6 Marks
Let assume a class having a string data member and an array of string variables. The application reads a
sentence from the user and stores each word of the sentence in the array. Users can enter a sentence of
any length. Length of the array will be decided at run time.
For example: “this is my object oriented program of text processing“
this is my object oriented progra of text processing
m
PMAS Arid Agriculture University Rawalpindi
University Institute of Information Technology
Solution:
#include<iostream> #include<string> using namespace std;
class sentence
{ /////////////////////// Data Members //////////////////////////////
string sentence;
string *words;
int size;
///////////////////////////////////////////////////////////////////
public:
void getdata()
{ cout<<"Enter sentence: ";
getline(cin, sentence); //////////// Getting
string///////////
size=0; int n=0;
while(sentence[n]!='\0') //////// Loop for Word count /////////
{ n++;
if(sentence[n]==' ')
{ size++; }
}
if(sentence[1]!='\0')
size++;
words=new string[size]; //////////// Dynamic Array of
Strings///
int j=0;
string temp="";
for(int l=0;l<n;l++) /////////// Loop for
Tokens ///////////
{ if(sentence[l]==' ')
{ words[j]=temp;
temp="";
j++; continue;
}
else if(l==n-1)
{ temp=temp+sentence[l];
words[j]=temp;
temp="";
j++;
continue;
}
else
temp=temp+sentence[l];
}
}
void putdata() ///////////////// Optional
Function//////////////
{ for(int s=0;s<size;s++)
cout<<" | "<<words[s]; cout<<" |"<<endl; }
PMAS Arid Agriculture University Rawalpindi
University Institute of Information Technology
};
int main()
{ sentence s;
s.getdata(); }

Question #2: 8 Marks


Let assume Stack can store different digits, but sometimes the user is interested to write the complete
name of the digit such as one, two, three etc and sometimes 1, 2, 3. Write a complete class which gives
freedom to the user to create stack objects of their own choice.
Solution:
#include<iostream> #include<string> using namespace std;
template<class T> //// Template variable //////
class stack
{ T a[10]; /// Data Members ///////////
int top;
public:
stack(){ top=-1; } /// Initialization /////////
void push(T x) /// Push Function //////////
{
if(top<9)
a[++top]=x;
else
cout<<"stack is full\n";
}
T pop() /// Pop Function //////////
{ if(top>-1)
return a[top--];
else
{
cout<<"stack is empty\n";
}
}
};
int main()
{
stack<int> s; /// Object of template class//
stack<string> s2;
s.push(10);
s.push(11);
s.push(12);
s2.push("Kashif");
s2.push("Sattar");
s2.push("UIIT");
cout<<s.pop()<<endl;
cout<<s.pop()<<endl;
cout<<s.pop()<<endl;
cout<<s2.pop()<<endl;
PMAS Arid Agriculture University Rawalpindi
University Institute of Information Technology
cout<<s2.pop()<<endl;
cout<<s2.pop()<<endl;
}

Question #3: 8 Marks


You are going to develop an application for arid university, consider the following scenario and write the
necessary code to implement the scenario:
 A university offers degrees to students.
 The university consists of one or more departments.
 Each degree is administered by a single department.
 Each student is studying towards a single degree.
 Each degree requires one to 20 courses.
 A student enrolls in 1-6 courses (per semester)
 A course can be either graduate or undergraduate, but not
both.

Solution:
For Q3, there is no specific solution. We need to check that whether students have created the following
classes...
class University{};
class Department{};
class Student{};
class Degree{};
class Graduate: public Degree {};
class PostGraduate: public Degree {};

Question #4: Understand the given code and write the missing code. 8 Marks
public class Vehicle {
public:
virtual void start()
{ cout<<”Let us start the vehicle”<<endl;
}
};
int main()
{ Vehicle vehicles[3]; //A correction is required in this line
vehicles[0] = &Car //Car is a class and there is no type casting required
vehicles[0] start(); //This should display “Turn key to start the engine”
vehicles[1] = &Bike;
vehicles[1] start(); //This should display “Kick to start the engine”
vehicles[2] = &LuxuryCar
vehicles[2] start(); //This should display “Push the START button to start the engine”
}
PMAS Arid Agriculture University Rawalpindi
University Institute of Information Technology
Solution:
#include<iostream> using namespace std;
class Vehicle
{ public:
virtual void start()
{
cout<<"Let us start the vehicle"<<endl;
}
};
class Car: public Vehicle
{ public:
void start()
{
cout<<"Turn key to start the engine"<<endl;
}
};
class Bike: public Vehicle
{ public:
void start()
{
cout<<"Kick to start the engine"<<endl;
}
};
class LuxuryCar: public Vehicle
{ public:
void start()
{
cout<<"Push the START button to start the engine"<<endl;
}
};
int main()
{
Vehicle *vehicles[3]; //A correction is required in this line
Car car;
vehicles[0] = &car; //Car is a class and there is no type casting required
vehicles[0]->start(); //This should display "Turn key to start the engine"

Bike bike;
vehicles[1] = &bike;
vehicles[1]-> start(); //This should display "Kick to start the engine"

LuxuryCar luxuryCar;
vehicles[2] = &luxuryCar;
vehicles[2]->start(); //This should display "Push the START button to start the engine"
}
PMAS Arid Agriculture University Rawalpindi
University Institute of Information Technology
Final Term Paper (Spring-2022)
BSCS/BSIT/BSSE (Morning/Evening)
Object Oriented Programming (CS-423)
Maximum Marks: 20 (Practical) Total Time: 45 min
-------------------------------------------------------------------------------------------------------------------------------
Question #1: [4+4=8 Marks]
Assume you have a UIIT-Faculty information system and assume you have a Password class having data
members (login and password) and member functions getData(). You need to include the following
functionalities:

A. Add another function passwordVerify( ) which calls getData() function and verify the
user data with the data stored (login and password) in the file “PwdFile.txt”
B. You need to add the code in the Password class, which handle the exception i.e. if the
user password is more than 8 characters, it will throw an Exception having the
information (length and a message “Is invalid length”).

Question #2: [4 Marks]


Based on the Scenario in Question #1, you need to add another function updatePassword() which calls
passwordVerify() function (defined in Q1-A) and if it returns true then it will update the new password in
the file “PwdFile.txt”. You can use getData() function to get the new password.

Note: write main function to support your functions but it is optional and has no marks.

Question #3: Discuss your course project in 2-3 lines [8 Marks]

You might also like