0% found this document useful (0 votes)
50 views2 pages

Assignment 1 CPE

OOP practice problems

Uploaded by

BABLU MUSIX
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)
50 views2 pages

Assignment 1 CPE

OOP practice problems

Uploaded by

BABLU MUSIX
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/ 2

Capital University of Science and Technology

Department of Electrical and Computer Engineering

CPE2123: Object-Oriented Programming, Fall 2024


Assignment No. 1
Instructor: Tooba Masood Date: 26/10/24
Total Marks: 10 Due Date: 30/10/24

Instructions: (can be changed accordingly)


 Assignment should have compiler generated outputs.
 Assignment should be submitted on or before due date.
 Copied assignments will get zero credit.

USE THE CONCEPTS OF


CLASSES and CONSTRUCTORS
Task 01:
Write a program that declares a class with one integer data member and 2 member
function setter() and calculate().
The setter() function should take input in integer data member. Take input from user. Then
calculate() function should calculate the sum of this integer value with the second integer
value that is passed to the calculate() function from the main body.
Task 02:
Write a program that declares a class with 2 variables, one constructor and one member
function.
Within constructor, assign values to these variables by passing parameters to the
constructor from main function.
Within first member function calculate difference of two values if first value is greater than
second value. Calculate sum if second value is greater than first. Return the calculated value
to the main function and display the result.

Task 03:
Write a class Result that contains roll no, name, and marks of three subjects. The marks are
stored in an array of integers. The class also contains the following member functions:
The input() function is used to input the values in data members. The total() function returns
the total marks of a student.
Define the functions within the class. Lastly, create a pointer to the object and use that
to input values and display sum.
Task 04:
Write a program that declares a class xyz with private data members: id, pages and price
of a book.
Define member function outside class. Program should define an array as an object of
class, inputs the records of three books via input() member function, calculate the most
expensive book in main function, and displays the record of most costly book in
expensive() function.

Help: To calculate most expensive book in MAIN FUNCTION you have to use getter
functions for price.

Task 05:
Passing object to the class function

Declare a class that contains an integer data member and 2 member function: input() &
output(). Create two objects: obj1 and obj2. Input integer value in input() function using both
objects. Calculate sum of values of both objects and display result in output() function by
passing obj2 to the output() function.

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