Spring 2023 - CS304 - 1

You might also like

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

Total marks = 20

Object Oriented
Programming (CS304) May 20th
Assignment # 01 , 2023
Spring 2023
Please carefully read the following instructions before attempting the assignment.

RULES FOR MARKING


It should be clear that your assignment would not get any credit if:
▪ The assignment is submitted after the due date.
▪ The submitted assignment does not open or the file is corrupt.
▪ Strict action will be taken if the submitted solution is copied from any other student or
the internet.

You should consult the recommended books to clarify your concepts as handouts are not
sufficient.

Topic Covered:

● Lecture 01-09

Uploading instructions:

● Your assignment should be in .CPP format (Any other formats like scan images, PDF, zip,
doc, rar and bmp etc. will not be accepted).
● Save your assignment with your ID (e.g. bc000000000.CPP).
● No assignment will be accepted through email.

NOTE

No assignment will be accepted after the due date via email in any case (whether it is the case of
load shedding or internet malfunctioning etc.). Hence refrain from uploading assignments in
the last hour of the deadline. It is recommended to upload the solution file at least two days
before its closing date.

If you find any mistake or confusion in the assignment (Question statement), please consult
with your instructor before the deadline. After the deadline, no queries will be entertained in
this regard.

For any query, feel free to email me at:


cs304@vu.edu.pk

Question Statement Marks (20)

Suppose a university wants to keep track of its students' information, such as their name, age, and student ID,
for various purposes such as enrollment, attendance, and grading. The university could create a Student class
that includes these member variables to represent each student, and use the class to store and manipulate the
information of each student.

Considering the given scenario create a C++ program with Student class that includes three member variables:
name, age, and studentId, and provides a default constructor, a parameterized constructor, a copy constructor
that performs a shallow copy, and an assignment operator that performs a deep copy. The main function
creates three Student objects using different constructors, and demonstrates the differences between shallow
and deep copying by modifying one object's name and printing the values of all three objects. The Student class
could be used in a real-life scenario such as a university keeping track of students' information for enrollment,
attendance, and grading purposes.

Class Name: Student


- name: string
Data
Members - age: int
- studentId: int

- Default constructor
- Parameterized constructor
- Copy constructor (shallow copy)
- Assignment operator (deep copy)
- Getter method for name
Methods - Getter method for age
- Getter method for studentId
- Setter method for name
- Setter method for age
- Setter method for studentId
- Print method to display student info

- Creates s1 using parameterized ctor


- Creates s2 using copy constructor
Main - Creates s3 using assignment operator
- Modifies name of s1
- Prints all three Student objects
Sample Output:

Note: Student will use their own name and Student ID as an input.

Best of Luck

You might also like