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

Assignment

The document contains instructions for a computer science assignment with 10 questions. Students are asked to write C++ classes to model fractions, polynomials, a library system, a shop with employees, inheritance between classes, and comparisons of objects. They are instructed to use operator overloading, friend functions, and other OOP concepts. Code must include comments and output screenshots. Files should be named and submitted correctly on Google Classroom.

Uploaded by

acernitro88588
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Assignment

The document contains instructions for a computer science assignment with 10 questions. Students are asked to write C++ classes to model fractions, polynomials, a library system, a shop with employees, inheritance between classes, and comparisons of objects. They are instructed to use operator overloading, friend functions, and other OOP concepts. Code must include comments and output screenshots. Files should be named and submitted correctly on Google Classroom.

Uploaded by

acernitro88588
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

National University of Computer and

Emerging Sciences

Assignment

Spring 2022

Deadline
As Mentioned on
Google-Classroom

Department of Computer Science


National University
of Computer & Emerging Sciences -Faisalabad

Guidelines
 Questions should be in order.

 There Should be a brief description of each line of code via Comments

 Above two instructions carry Marks

 Add a Screenshot of console output with your code.

 .DOCX file naming format should be ‘Rollno_Section_A#3’ and submit this


document on Google Classroom.
 This is an individual assignment. PLAGIARISM IS NOT ACCEPTABLE!
 Follow the instructions.

Q1: Create a class for fraction that will store denominator and nominator. You must
provide the functionality of sum multiply subtract and divide.
For operations you must use operator overloading and friend function for input and
output. Make a diver function that will call all the functions.

Q2: Create a class for polynomials that will store a polynomial with a user defined
degree. Degree of a polynomial is the maximum number of power that it has.
You must provide the functionality of sum multiply subtract and divide. For operations
you must use operator overloading and friend function for input and output. Make a diver
function that will call all the functions.

Q3: Create a library system where you will have a class of books and students and the
librarian will operate through main function a student can get maximum 10 books from
library. and on late there will be a fine 5RS per hour and on return the system must tell
the fine on the book

Page 2 of 6
National University
of Computer & Emerging Sciences -Faisalabad

Q4: Write a class of shop with member variable ID, name, post, salary, status.
Post:
1. Owner
2. Salesman
3. Manager
Status: string type--- working / not working
In main function, you have to take array of 5 objects and overload the following
operators.
 + : (to calculate the sum of all employees)
 - : (to update the working status)
 * : (to increase the salary 10% of specific worker with his ID)
 >> : (to input)
 << : (to display)
 ++ : (to increment in salary 5000)
 --: (to decrement in salary 5000)
 == : (to display all the employees have equal salary)
 != : (to display all the employees have unequal salary)

Q5:
1. Write a class Base having the following integer attributes:
• Base1
• Base2
• Base3(private)
Write a default constructor for Base that should initialize all the attributes to “0”. Write an overloaded
constructor that should initialize all the attributes to the passed integer. Write a display method to display
the attributes of Base class.

2. Publicly inherit a Derived class from Base class. Derived should have an integer attribute:
• Derived1
• Derived2(private)
Write a default constructor for Derived that should initialize all the attributes (inherited and self)to “1”. Write
an overloaded constructor that should initialize all the attributes to the passed integer. Write a display
method to display the attributes of Derived class.

Page 3 of 6
National University
of Computer & Emerging Sciences -Faisalabad

3. Write a class Friend_Class. Make it a friend of Base Class.


Write a method accessMethod() in Friend_Class class.
Access the members of Base class in this method(public and private).

4. Write a class Friend1_Class. Make it a friend of Derived class.


Write a method accessMethod()1 in Friend1_Class class.
Access the members of Derived class in this method(public and private).
5. Write a class Friend2_Class. Make it a friend of Friend_Class.
Write a method accessMethod() in this Friend2_Class class.
Access the members of Friend_Class in this method and also the members of Base Class (check whether
you can access its public and private).

Q6:

Q7:

Page 4 of 6
National University
of Computer & Emerging Sciences -Faisalabad

Page 5 of 6
National University
of Computer & Emerging Sciences -Faisalabad

Q8: Write a program that Compare the two object that contains integer values that
demonstrate the overloading of equality (= =), less than (<), greater than (>), not equal ( !
= ),greater than or equal to (>=) and less than or equal to(<=) operators. Show the output
for if 2 numbers from 2 objects are equal, not equal, less than or greater than equal

Q9: (Polynomial Class) Develop class Polynomial. The internal representation of a Polynomial
is an array of terms. Each term contains a coefficient and an exponent, e.g., the term 2x4 has
the coefficient 2 and the exponent 4. Develop a complete class containing proper constructor
and destructor functions as well as set and get functions. The class should also provide the
following overloaded operator capabilities:

a) Overload the addition operator (+) to add two Polynomials.


b) Overload the subtraction operator (-) to subtract two Polynomials.
c) Overload the assignment operator to assign one Polynomial to another.
d) Overload the multiplication operator (*) to multiply two Polynomials.
e) Overload the addition assignment operator (+=), subtraction assignment operator (-=),
and multiplication assignment operator (*=).

Q10: Create a class Mobile having Specification attributes and a friend function Compare.
Show a list of available mobiles to the user and compare them to help the user make a decision
to buy the better one. Put some intelligence in your program to predict him which one is the
better phone.

Page 6 of 6

You might also like