Assignment1_Updated
Assignment1_Updated
Assignment # 1
Subject: Object Oriented Programming & Design Course Code: CS - 112 - I, - Spring - 25
Class: BS DS– 2nd Submission Deadline: 06/Feb/2025 - Thursday (5:00 - PM)
Course Instructor: Nazia Shahzadi - Lecturer - FCSE Total Marks: 40 (Marks are divided problem wise)
• First of all, read the instructions and statements of each exercise/question carefully then write the solution.
• It is written in front of each question that you have to upload it as handwritten or C++ code file.
• For Handwritten:
o In case of multiple questions, give heading of each question’s number or the task you are going to solve (don’t
write statement of question)
o Mention page number and your roll number at corner of each page.
o Take pictures using applications like camscanner on your phone.
o Then select all pictures in the camscanner application and convert them into a pdf file using pdf option in
application.
o The name of your pdf file should contain your assignment number and your roll number as shown in following
example, For Example if your roll number is 2024532 and you have done assignment number 2 then the name
of file should be as ---> 2024532_2.pdf
o Then upload that pdf file at Microsoft teams. Remember the sequence of pages should be right.
o Also keep the same original pages/hardcopy with you so that you can show/submit me later if required.
• For C++ Code File:
o Create different file for each task & assignment (way of naming file mentioned in each task).
o Submit your assignment in hard form/printed as well.
• Zip Folder containing handwritten PDF and C++ files:
o Store all handwritten pdf and C++ files in a single zip folder named as “YourRegNo_AssignmentNo” as shown in
following example, For Example if your roll number is 2024532 and you have done assignment number 2 then
the name of file should be as ---> 2024532_2.zip
CHEATING/COPY CASE or LATE SUBMISSION even 1 minute late will be graded as STRAIGHT ZERO MARKS .
So be on time make no excuse.
TASK – 1: Basic Practice of Structures, Unions, Enumerations, Functions & Arrays. Marks: 25
(Hand-Written & C++ Code file in Zip Folder)
For this task – 1 you will need to create two files.
(i) yourRegNo_task_1 .cpp (ii) yourRegNo_definitions_1.cpp
For example: 2024008_task_1.cpp 2024008_definitions_1.cpp
1) Create Structures, Unions, Enumerations, Arrays as mentioned following:
(Marks: 3+2+2+1 = 8)
a. Structure: “Address” with two variables “city” and “street”.
b. Structure: “Foreigner” with variables “f_visitorNo” and “f_passportNo”
c. Structure: “National” with variables “n_cnic” and “n_familyNo”
d. Union: “PersonType” with variables “p_foreigner” of Foreigner type (structure already created
in point no b) and “p_national” of national type (structure already created in point no c).
e. Enumeration: “GENDER” that contains two values “Male” & “Female”.
f. Structure: “Person” with variables “string p_name”, “int p_age”, “Address p_address”,
“PersonType p_type”, “Gender p_gender” also create an array in “Person” named as “string
p_degrees[3]” so that we can store any degrees like BSCS, MSCS or PHD CS later on.
g. Array: “person_Record” of “Person” type to store data of 5 persons later on.
Page 1
2) Use main function to create “p1” of “Person” type to cin all data of a p1.
(Marks: 2)
3) Create a function “void coutPersonRecord (Person person)” outside of structure to display output of all
data of “p1” you created in main() by passing the “p1” as value to the above created function.
(Marks: 3)
4) Create a function “editPersonRecord” outside of structure to edit data of a single Person “p1” you
created in main() by passing the “p1” as reference to the above created function.
(Marks 7)
a. The function “editPersonRecord” will contain if conditions / switch statements to ask user that
what kind of value he/she wants to edit. For example, it can ask to user on screen in following
way:
5) Finally now copy all code written above / outside the main() in another cpp file named as
“yourRegNo_definitions_1.cpp” for example “2024008_definitions_1.cpp” and include this file using
#include and pre-processor directives in your current file. And call all functions/structures similarly as it
was done previously in main() before copy.
(Marks: 5)
TASK – 2: Passing arrays as reference to function and manipulating it with loops. Marks: 15
Details about working of program we are going to build in task – 2
Previously we successfully stored data of single person in our program but In this task we want to store record
of more than one person (At this point we are limiting our software to store data of 5 persons only) in our
program the working of program will be as following:
I. In start program will cout and tell user that it can store record of only 5 persons (for this purpose we will
be creating / using the array named as “person_Record” as we created in task – 1).
II. To insert or display from the array we will be the using functions those functions will address of arrays
passed using pointers then functions will use the loops to move on different addresses of arrays.
III. But it depends on the user how many records he adds, maybe he adds only one record to array, or he may
also 3 or 5 records. So, what should be done to manage how many times the loop will run?
IV. Remember we will not change the size of array we will keep size of array equal to 5 as we mentioned
previously that our array is limited to store 5 records, but we will have to manage that how many time our
loop will run to store records in array (remember it should not run more than 5 time as this is the upper
limit).
V. We will manage it according to the number of records for which data is inserted. Every time when user
enter the record of one person then code in loop should ask user that do, he/she wants to enter more
records (you can as user to press 1 to enter more records or press 0 otherwise) if user says yes then loop
will run again to store next records otherwise it will stop loop using break statement and exit function that
was being used to insert data in array. Now for example if you entered the 3 records it means that loop in
insert function ran 3 times.
VI. It means the loop in another function to show output of data should also run 3 times because only 3
indexes of array contain data. It not necessary for value to be 3 because it depends on user and may be
different each time because we don’t know that for how many persons data will be stored.
VII. To solve this issue, you should store this number of iterations (means number of time loop ran in insert
function) in some other global variable so that it can be used later on in other function that will be used to
show output of data of all records from array.
Page 2
VIII. For this task – 2 you will need to create two files:
(i) yourRegNo_task_2 .cpp (ii) yourRegNo_definitions_2.cpp
For example: 2024008_task_2.cpp 2024008_definitions_2.cpp
1) In this task we will be creating the same structures/unions/enums that you were asked to create in point
1 of Task # 1. We will create a similar array named as “person_Record” in main () for inserting the data
of 5 persons (As we created in sub point “g” of point number 1 of previously mentioned Task - 1). Initially
you will create everything in file (i) yourRegNo_task_2 .cpp
(Marks: 1)
2) To insert data in above mentioned array we will create a function named as “insertNewRecord” this
function will use pointers to take address of array from main() then it will add data to each index of array
using loops in functions (As per process mentioned in details section of task – 2 on previous page # 2).
You will have to create a global variable named as “number_of_records” this variable will store number
of times the loop ran in “insertNewRecord” function to store data (As mentioned in point no. III and
onwards in details section on previous page # 2.)
(Marks: 6)
3) Then you will create another function named “showAllRecords” to display all records that were inserted.
This function will use pointers to take the address of array from main() then it will show data at each
index of array using loops in functions. The upper limit of loop should be equal to the value stored in
variable “number_of_records”. So that the iterations of loop can be run only according to the number
of records stored in the array.
(Marks: 6)
4) Finally now copy all code written above / outside the main() in another cpp file named as
“yourRegNo_definitions_2.cpp” for example “2024008_definitions_2.cpp” and include this file using
#include and pre-processor directives in your current file. And call all functions/structures similarly as it
was done previously in main() before copy.
(Marks: 2)
Note: Copy all files of task 1 & 2 in single zip folder as mentioned above.
Page 3