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

CE101T – Object Oriented Programming

Section: Assignment # 4 Total marks: 35

Name : __________________ Roll number : __________________

Submission:
• Email instructor or TA if there are any questions. You cannot look at others’ solutions or use
others’ solutions, however, you can discuss it with each other. Plagiarism will be dealt with
according to the course policy.
• Submission after due time will not be accepted.

Follow this naming convention for your report, it should highlight difficulties you faced and things you
learned in this assignment. Naming Pattern ( Roll#_Assignment#.pdf e.g BSCE23000_Assignment3.pdf )
In this assignment you have to do following tasks:
Task 1: Ensure that you have installed all three softwares in your personal computer (Github,
Cygwin & CLion). Now, accept the assignment posted in Google Classroom and after accepting,
clone the repository to your computer. Make sure you have logged into the github app with your
account.
Task 2: Open Cygwin app, Move to your code directory with following command “cd
<path_of_folder>”
<path_of_folder> can be automatically populated by dragging the folder and dropping it to the
cygwin window.
Run the code through Cygwin, use command “make run”, to get the output of the code
Task 3: Solve the given problems, write code using CLion or any other IDE.
Task 4: Keep your code in the respective git cloned folder.
Task 5: Commit and Push the changes through the Github App
Task 5: Write the code in separate files (structure_name.h, structure_name.cpp) for each struct, declare
struct variables, and call functions from main.cpp. Ensure that file names are in lowercase.
Task 6: Run ‘make run’ to run C++ code
Task 7: Run ‘make test’ to test the C++ code

Object Oriented Programming


CE101T-Spring 2024
Problem Statement: Handling Individual Records
Declare a structure named "Person," which includes the following attributes:
Name (string), comprising both first and last names separated by a space.
Age (integer).
Array of salaries for the last five months (integer).

Note: Proceed with the previous lab 4 and incorporate the following functions to complete
assignment 4.
Functions in lab 4 addPerson(), updatePerson(), and displayPerson() were for single JSON
object. Implement the below functions for an array of JSON objects.

Part 1: Add Person


Implement a non-member default function named addPersonInJSONArray, which reads an
array of JSON objects from a file (persons.json). Create a new JSON object and initialize its
keys with the properties of the Person structure. Add the JSON object to the array and write the
updated array of JSON objects back to the file (persons.json).
Note: File persons.json with empty array [] must exist. Do not add person if already exist and
with empty salary array.

Part 2: Find Person by Name


Implement a non member function named findPersonbyName that accepts a name parameter.
This function reads a JSON file, traverses the JSON array, finds the object by name, and displays
its properties in the following format:
Name: Mustafa Kamal
Age: 34
Salaries: 3400 4300 2300 1200 5400

Part 3: Find Person with Highest Average Salary:

Object Oriented Programming


CE101T-Spring 2024
Implement a non-member function named findPersonWithHighestSalary that searches for a
person by reading an array of JSON objects from a file. The function identifies the person with
the highest average salary and returns this highest average salary value.

Part 4: Updating Person's Age by Name:


Implement a non-member function named updatePersonByName, which accepts parameters for
the name and updated age. This function reads a JSON array from a file, traverses the array,
updates the age of the person by name, and returns the index of the JSON object within the array
of JSON objects otherwise return -1 if not found.
Note: Do not update age if a negative integer is provided in this case return -1.

Part 5: Delete Person by Name:


Implement a non-member function named deletePersonByName, hich accepts a name
parameter. This function reads a JSON array from a file, traverses the array, finds the person by
name, removes them from the array of JSON objects, and then writes the updated array back to
the file.

Part 6: Display All Person


Implement a non-member function called display to output information about all individuals by
parsing data from a JSON file formatted in JSON.
Sample Output:
[
{
"age": 46,
"name": "Mobeen Zahid",
"salaries": [
3000,
3200,
3100,
3300,
3400
]
},
{
"age": 25,

Object Oriented Programming


CE101T-Spring 2024
"name": "Atique Ahmed",
"salaries": [
3000,
3700,
3400,
3100,
1400
]
},
{
"age": 35,
"name": "Faisal Bhula",
"salaries": [
1000,
3700,
1400,
1100,
1400
]
},
{
"age": 25,
"name": "Shahzad Ahmad",
"salaries": [
3000,
3700,
3100,
3100,
3400
]
},
{
"age": 15,
"name": "Shareef Gujjar",
"salaries": [
4700,
3200,
4400,
3100,
400
]
}
]

Object Oriented Programming


CE101T-Spring 2024

You might also like