Professional Documents
Culture Documents
SCIENCES ISLAMABAD
Object Oriented Programming Fall 2023
ASSIGNMENT # 02
Q1. A program calculates performance-based salary of customer support representatives (CSRs)in an organization.
Implement a class CSR (Customer support representative) with the following private datamembers:
1. int csrID – a integer to hold employee identification numbers between 1 and 7.
3. int hours – an integer to hold the number of hours worked by each CSR
4. int complaintsResolved – an integer to hold the number of complaints successfullyresolved by each CSR
5. float payrate – a float to hold the employee’s hourly pay rate, where payRate is calculatedas following:
payRate = $25 + 25*(complaintsResolved by each CSR/total complaints resolved)
6. float wage – a float to hold the employee’s wage, calculated aswages = hours * payrate
7. static int totalComplaintsResolved - a static integer to hold the total number ofcomplaints resolved by all CSRs
14. static int getTotalCpsResolved() – a static function to get total complaints resolved
Implement the following functions in global scope. All functions will take an array of CSR objectsas an argument.
3. void calcAllEmployeeWages(CSR employees[7]) – a function that calculates the wages ofall employees
4. void SortByHours(CSR employees[7]) – sorts employees in descending order based onhours worked.
Note: Ensure all necessary input validation, for example, hours, complaintsResolved cannot be negative numbers. Also assume, no
two CSRs will have the same number of hours, complaintsResolved and wages.
Total Marks: 60
Q2: Implementation of Matrix Class – Your goal is to implement a generic “Matrix" class. You will need
to write two files (matrix.h, matrix.cpp). Your implemented class must fully provide the definitions of
following class (interface) functions.
class Matrix{
1. int **matrix – a double pointer of type integer to create a 2D array which is your matrix
2. int row – an integer to store the rows in the matrix
3. int col – an integer to store the columns in the matrix
public:
//include all the necessary checks before performing the operations in the functions
Matrix();// a default constructor
Matrix(int, int);// a parametrized constructor
Matrix(const Matrix &);// copy constructor
void set(int i, int j, float val);//set value at (i,j)
float get(int i, int j)const; //get value at (i,j)
Matrix multiplyElement(const Matrix);//Elementwise multiplies two Matrices and returns the result
void makeZero(); //if the any element in the matrix is zero than make the entire row and column
zero.
Example:
5 8 8 9 5 5 8 0 9 5
1 2 0 6 3 0 0 0 0 0
8 4 3 9 4 8 4 0 9 4
bool searchNumber(int number); // if the number exist in the matrix return true. Else return false.
You can make the number by using digits from cells that are next to each other, either up and
down or side to side. But you can't use the same cell with the same letter more than once.
Each cell contains single digit at max.
Example: In this case your function should return true. Number = 2581349
9 6 4 4 2
9 6 4 4 2
3 9 7 8 5
3 9 7 8 5
6 4 3 1 4
6 4 3 1 4
void rotateBy90(); // You have to implement the logic to rotate your matrix by 90 degrees anti-
clock wise.
Example:
9 6 2 2 5 4
3 9 5 6 9 4
6 4 4 9 3 6
int LeftDiagonalTotal() - Calculates and returns the total sum of the values in the left Diagonal ofarray.
int RightDiagonalTotal() - Calculates and returns the total sum of the values in the right Diagonal ofarray.
Total Marks = 50
Q3: Implement your own string class using only primitive data types. Your string class should containsome of the
same functionality as the string class in C++.
6. void findMinStr(char* secretStr); // decalare variable char* magicStr = data in this function only;
There was a programmer named Alex in the kingdom of Codeville who held a magical string called "magicStr."
Lily, a fellow developer, asked Alex for assistance in locating the smallest substring within "magicStr" that
included all of the characters from her string "secretStr." To accomplish this goal, Alex wrote a powerful
function called findMinStr, which returned the "Not Found" if it did not exist. Because of its exceptional skills,
its magical function became famous among coders, facilitating the search for hidden gems inside strings.
Example:
magicStr = “iamastudentoffastnuces.”
secretStr = “fasces”
7. bool equalsIgnoreCase(char* str): this method compares the calling string objectdata with the data in str
without considering the case.
8. char* substring(char* substr, int startIndex) : this method should search for substrin data within the calling
String object starting from the startIndex. The methodshould search for the substring from the startIndex and
return the substring from the position found till the end. For example, if you had the string “awesome” andyou
wanted to find the substring ‘es’ starting from the beginning of the string(startIndex = 0). Your function
should return “esome”. Returns NULL if substring isnot found.
9. char* substring(char* substr, int startIndex, int endIndex) : this method should search for substr in data
within the calling String object between the startIndex and endIndex. For example, if you had the string
“awesome” and you wanted to find the substring ‘es’ starting from startIndex=2 and endIndex=5. Your function
shouldreturn “esom”. Returns NULL if substring is not found.
10. Once upon a time, in a magical land called Chromaland, there was a special version of a game called "Color
Challenge." In this exciting game, there was a line of colorful balls on a board. Each ball had its own color: bright
red ('R'), sunny yellow ('Y'), deep blue ('B'), fresh green ('G'), and pure white ('W'). The goal was simple: you
needed to get rid of all the balls from the board.
You had some colorful balls in your hand, just like the ones on the board. These balls were your tools to win the
game. Here were the rules:
1. On your turn, you could pick a ball from your hand and place it between two balls on the board or at either
end of the line.
2. If you put a ball in a way that made three or more balls of the same color next to each other, those balls
vanished from the board.
3. If this made more groups of three or more balls of the same color, you had to keep removing them until there
were none left.
4. If you managed to remove all the balls from the board, you won the game and became a hero!
Your job was to figure out how to use the balls in your hand wisely to clear the board with as few moves as
possible. In this scenario your function should return the number of balls used to win the game by your hand
string. But there was a challenge: if you couldn't clear the board with the balls in your hand, you'd lose, and your
function should return -1.
int ColorChallange(char* hand); // declare variable char* board = data; for this function
TestCase 1:
TestCase 3:
Question 4 30 marks
Implement a structure Address with the following data members:
The following two will be passed as arguments to all the global functions mentioned below.
15 Marks
Implement a class Sandwich that includes the following private data members:
Happy Coding 🙂