Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Homework 3 CSE 1310 Introduction to Computers and Programming Fall 2022 Submission Deadline: Tuesday, 11/08/2022, 11:59 PM Instructions: • For each problem, your code must...

1 answer below »
Homework 3

CSE 1310 Introduction to Computers and
Programming
Fall 2022

Submission Deadline: Tuesday, 11/08/2022, 11:59 PM


Instructions:
• For each problem, your code must compile without
e
o
warning and produce the required output, a 0 grade
will be assigned otherwise for that problem.
• No partial credit will be given for code that does not cleanly
compile.
• Submit one StudentName_ID.c file with all the codes
within that single file.























1. Write a function named gradeEval to evaluate the grade received by a student
using the following parameters:
Marks >= 90 : Grade A
Marks >= 80 : Grade B
Marks >= 70 : Grade C
Marks >= 60 : Grade D
Marks >= 40 : Grade E
Marks < 40 : Grade F
The function should take an integer as the input parameter and return a character
output. In the main program, take 4 user inputs for the Physics, Chemistry,
English, and Mathematics marks received by a student. Print a report card for the
grades that the student has received.
A sample output for a student who has received 84 in Physics, 71 in Chemistry,
68 in English, and 22 in Math would be:
REPORT CARD
Physics: B
Chemistry: C
English: D
Mathematics: F
Note: This is a similar question to one you’ve already solved in HW2. This time,
instead of writing multiple switch/case or if-else blocks, you need to write only
one in the function, and call that function 4 times in the main program to
evaluate the grades for all 4 subjects.

2. Take two numbers as user input, and store them in the variables x and y.
Generate a random integer between 1 to 4 using the rand() function and store it
in the variable calc. Print the value of the calc variable. Then use switch-case
statements to perform the following calculations
If the value of calc is 1, print the value of x+y
If the value of calc is 2, print the value of x-y
If the value of calc is 3, print the value of x*y
If the value of calc is 4, print the value of x/y
Sample output:
Please enter the value of x: 10
Please enter the value of y: 20
Randomized value of calc is: 3
Your output is x*y = 200
Note: Please convert explicitly to float wherever required (i.e. for division
operation)

3. Write a C program to create a function print_average with 3 parameters that
calculates AND prints the average of the 3 numbers passed to it. In the main
program, take user inputs for 3 numbers and print their average using the
print_average function. Do NOT write a print statement in the main function
other than the one(s) prompting the user for input.
Sample output:
Enter the first number: 10
Enter the second number: 20
Enter the first number: 30
The average of 10, 20, and 30 is 20.

4. Write a C program to take four integer inputs/values from the user and store
them in an integer a
ay. Print the a
ay in a single line. Then ask the user to enter
an index/position of the a
ay between 0 to 3, and print the value co
esponding
to that index in the a
ay. After that, ask the user to enter two indices between 0
to 3, and swap the values of the respective indices, then print the updated a
ay.
Sample output:
Enter four numbers for the a
ay –
Enter a number: 10
Enter a number: 20
Enter a number: 30
Enter a number: 40
XXXXXXXXXX
Enter a position between 0 to 3 to print: 2
Value cu
ently present in index 2 is 30
Enter two positions of the a
ay to swap: 0 2
The updated a
ay is
XXXXXXXXXX

5. Write a C function named makeSquare with one parameter to take an integer
input and return the square of that integer. In the main function, take four
integer inputs from the user and store them in an integer a
ay. Print the a
ay in
a single line, then ask the user to enter an index value between 0 to 3. Print the
value cu
ently present in that index of the a
ay, and use the makeSquare
function to obtain its squared value. Update the given index value with the
squared value, and then print the a
ay.
Sample output:
Enter four numbers for the a
ay –
Enter a number: 10
Enter a number: 20
Enter a number: 30
Enter a number: 40
XXXXXXXXXX
Enter a position between 0 to 3 to square: 2
Cu
ent value of index 2 is 30
The updated a
ay is
XXXXXXXXXX

6. Write a C function named makeSquareDirectly with 3 parameters, the first being
an integer a
ay, and the second being an integer I, and the third being the
number of elements in the a
ay. This function should square the value of the ith
index of the a
ay, and then print the updated a
ay (Important! Printing the
a
ay should be done in this function itself!). In the main function, take four
integer inputs from the user and store them in an integer a
ay of length 4. Print
the a
ay in a single line, then ask the user to enter an index value between 0 to 3.
Square the value of the index and print the updated a
ay by using the
makeSquareDirectly function.
Sample output:
Enter four numbers for the a
ay –
Enter a number: 10
Enter a number: 20
Enter a number: 30
Enter a number: 40
XXXXXXXXXX
Enter a position between 0 to 3 to square: 2
Cu
ent value of index 2 is 30
The updated a
ay is
XXXXXXXXXX

7. Write a function called a
aySum to return the sum of all numbers in an int a
ay.
Write another function isOdd to evaluate whether an integer is an odd number.
In the main function create an int a
ay of size 5 and take user inputs for each
index in the a
ay. Using the a
aySum and isOdd functions, evaluate and print
whether the sum of all the numbers in the a
ay is odd or even.

Sample output:
Enter four numbers for the a
ay –
Enter a number: 10
Enter a number: 20
Enter a number: 30
Enter a number: 40
The a
ay is: XXXXXXXXXX
The sum of the numbers in the a
ay is even

8. Write a C function named makeSquare with one parameter to take an integer
input and return the square of that integer. In the main function, create a 3X2 2-
D a
ay, and take and store user inputs for all positions in the a
ay. Print the
a
ay, then ask the user to enter an value between 1 to 3. For the value entered,
call the makeSquare function on every element in the co
esponding row (e.g. if
user enters 2, call makeSquare on every element in the second row of the 2-D
a
ay) and update each element with the squared value. At the end, print the
updated a
ay

Sample output:
Enter 9 numbers for the a
ay:
Enter a number: 1
Enter a number: 2
Enter a number: 3
Enter a number: 4
Enter a number: 5
Enter a number: 6
The a
ay is
1 2
3 4
5 6
Enter the row to square: 3
The updated a
ay is
1 2
3 4
25 36
Answered Same Day Nov 08, 2022

Solution

Vikas answered on Nov 08 2022
42 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here