PF Assignment-03 Revised

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

Assignment-03

FALL 2023
Subject: Programming Fundamentals Total Marks: 10
Class: BS Computer Science Semester: 1st

WARNING
1. PLAGIARISM OR HIRING OF GHOST WRITER(S) FOR SOLVING THE
ASSIGNMENT(S) WILL DEBAR THE STUDENT FROM AWARD OF
DEGREE/CERTIFICATE. IF FOUND AT ANY STAGE.
2. SUBMITTING ASSIGNMENT BORROWED OR STOLEN FROM OTHER
STUDENT IS STRICTLY PROHIBITED

INSTRUCTIONS:
➢ This assignment contains a total of 10 Problem Questions.
➢ Submit the Assignment within the due date.
➢ You can get bonus marks by putting extra effort into proper documentation.
➢ To attempt this assignment, you should have full command of Lecture # 10 to Lecture 16.
➢ Try to make solutions by yourself and protect your work from other students. If we found
the solution files of some students are the same then we will reward zero marks to all
those students.
➢ Here is the recommended format to submit the assignment.
1. Mention the Problem No & Problem Statement.
3. give a heading of Code and past screen shot of the program.
4. Copy your error-free code from the compiler.
5. Paste it in your document file.
6. Then give a heading of Sample Output.
7. Execute your program & and take a screenshot of the output.
8. Crop the Dos Screen Area and Past it in document
Note:
“There are no shortcuts to success. The only way you can achieve success is to Work hard and
then pray a lot. Hard work always pays back in terms of benefits, satisfaction, experience, self-
confidence, respect and wealth. So never step back or shy to work hard and pray to be
successful.”
“It’s worth to give a sincere try to the hardest task you will ever face because completion of a
task is not in our hands, we can only work hard with sincerity and honesty and then pray to Allah
Taala because completion is in hands of Allah Almighty.”
“Always seek help in your brightest and darkest of times from Allah Taala and you will see that
He is always there for you to provide help with all of His blessings.”
I will be evaluating you by your sincere and honest efforts towards your task. Good luck!

Muhammad Imran Ali


Department of Computer Science,
Institute of Southern Punjab, Multan
Problem Sheet
Problem No 1: Describe the concept of iteration in programming and the need for loop
structures. Discuss the general types of loops available in C++, including the while loop,
for loop, and do-while loop. Explain the syntax and working principles of each loop type.
Provide examples to demonstrate the usage of loops for repetitive tasks and iterative
processing.

Problem No 2: Write a program that takes a course score (a value between 0 and 100) and
determines a student’s course grade. Your program should have three functions: main,
getScore, and printGrade, as follows:
1. main
a) Get the course score.
b) Print the course grade.
2. getScore
a) Prompt the user for the input.
b) Get the input.
c) Print the course score.
3. printGrade
c) Calculate the course grade.
d) Print the course grade.
The parameter of getScore function must be pass by reference.

Problem No 3: Write a program to perform the following operation using Functions.

A. Create a function that takes input marks of five subjects as a parameter and returns
the aggregate marks of a student.
B. Create a function that takes the aggregate marks as input and print grade according
to the following table.
Aggregate Marks Grade
85-100 A
70-84 B
60-69 C
50-59 D
Less than 50 F
Problem No 4:
Pakistan cricket board contains the following records of Pakistan cricket team members,
name of the cricketer, his age, number of test matches that he has played and the average
runs that he has scored in each test match.
A. Create an array of structure to hold records of 10 cricketers
B. write a program to read these records and arrange them in ascending order by
average runs
Problem No 5: Write a program that performs flowing tasks:
a) Initialize an integer array of 10 elements in main ().
b) Create a function sort () and pass an array as a reference parameter to sort
an array using the Insertion sort algorithm.
c) Create a function print () to print array by getting array as a parameter.
Problem No 6:

In a courier company, 10 boxes of given weight are available for delivery, you are
required to write a program to perform the following operation.

A. initialize an integer array of 10 elements in main () to keep a record of boxes and


their weights.
B. pass the entire array to a function Parcel-Price ().
C. in Parcel-Price () multiply each element of the array by 30 if item weight is less
them 5 kg otherwise multiply each element by 40.
D. return the control to main( ) and print the new array elements in main( )

Problem No 7: Imagine you are tasked with developing a program for a scientific
research team that analyzes experimental data stored in a 2D array. The team needs a
tool to efficiently input the data, print the diagonals of the matrix for a quick assessment,
and calculate the sum of all elements for further analysis.

Your assignment is to create a C program with three functions tailored for this purpose:

A. inputArray: This function should prompt the researchers to input experimental


data into a 2D array, representing the results of their experiments. Ensure the
program accommodates different matrix dimensions.
B. printDiagonals: Design a function that prints both the main diagonal and anti-
diagonal elements of the 2D array. This will aid researchers in identifying patterns
in the data.
C. sumOfElements: Develop a function that calculates the sum of all elements in the
2D array. This sum is crucial for deriving overall trends and averages from the
experimental data.

In your main function, demonstrate the functionality by declaring a 2D array, calling the
inputArray function to input experimental data, then using the printDiagonals function
to visually inspect diagonals, and finally, calling the sumOfElements function to obtain
the total sum.
Problem No 8: Imagine you are tasked with developing a program for a human
resources department that organizes and analyzes employee data stored in a 2D array.
Your goal is to create a C program with three functions suited for this HR application:

A. inputArray: Design a function that takes a 2D array as a parameter and allows


the HR personnel to input employee data into the array. The matrix should
accommodate various dimensions to represent data from different departments
or teams.
B. sortArray: Implement a function that sorts the employee data in the 2D array
based on relevant criteria, such as employee ID or salary. Sorting will facilitate
quick access to information and assist in identifying trends in the workforce.
C. searchInArray: Develop a function that takes an employee ID as input and
searches for its presence in the sorted 2D array. This function will be crucial for
retrieving specific employee details or confirming an employee's status within
the organization.

Problem No 9: two arrays of 10 elements are given blow, write a program to sort the
given array.
A[10]

15 18 44 64 78 95 78 55 76 12
Problem No 10: C program to perform matrix addition. Your program should take two
matrices as input, add them element-wise, and store the result in a new matrix. Follow
these guidelines to complete the program:

A. inputMatrices: Implement a function that takes two matrices as parameters and


prompts the user to input values for each element of both matrices.
B. addMatrices: Design a function that takes two matrices as parameters and
calculates the sum of corresponding elements, storing the result in a new
matrix.
C. displayMatrix: Develop a function to display the content of a matrix in a
readable format.

𝟏𝟓 𝟐𝟐 𝟐𝟎 𝟏𝟒 𝟐𝟏 𝟒𝟒
A = [𝟏𝟖 𝟏𝟎 𝟏𝟏[ B = [𝟔𝟔 𝟐𝟕 𝟑𝟐]
𝟏𝟒 𝟏𝟐 𝟑𝟑 𝟖𝟏 𝟐𝟑 𝟏𝟏

You might also like