@SLIIT

Introduction to Programming Continuous Assessments Questions and Answers

Assessment 4 – Functions

[1]   Version Alpha

You are asked to write a C program to calculate the increment given for employees.

Write a function called calcIncrement() to calculate and return the increment given for employees. The incrementamount is 10% of the salary. Increment is given only to the employees who worked more than 2 years. Function protype is given below.

float calcIcrement(float salary, int noofYearsWorked);

Write a function called calcTotalSalary() to calculate the total salary.
(total salary = salary + increment).

float calcTotalSalary(float salary, float increment);

In your main function, enter the salary of an employee and the number of years worked from the keyboard. Display the increment and total salary as follows using the functions created.

Enter salary :
Enter number of years worked :
Increment :
Total salary :

Solution



[2]   Version Bravo

A hotel has decided to offer 10% discounts from hotel charge for the wedding packages during the festive season. Discount is valid only if the number of guests is more than 200.
(Hotel charge = number of guests * charge per guest).

You are asked to write a C program to calculate the discount for the wedding package by considering the number of guests. Function should return the discount. Function prototype is given below.

float getDiscountPrice(int noOfGuests, float chargePerGuest);

Write a function called getAmount() to calculate the amount to be paid. Function prototype is given below.
(Amount to be paid = (no of guests * charge per guest) – discount)).

float getAmount(int noOfGuests, float chargePerGuest, float discount);

In your main function read the number of guests and the charge per guest from keyboard and display the discount and the amount to be paid for wedding package using the functions created above, in the following format.

Enter number of guests:
Enter charge per guest:
Discount:
Amount to be paid:

Solution



[3]   Version Charlie

A security firm has categorized their employees into three grades and a hourly rate is paid based on the grade as follows.

Grade Hourly Rate(Rs)
1 100.00
2 200.00
3 300.00

Implement a function called calculateWeeklySalary() to find and return the weekly salary of an employee. Total number of hours worked during the week and the grade of the employee should be passes as a parameter. Function prototype is given below.

calculateWeeklySalary(int grade, float hrsWorked);
(Weekly salary = number of hours worked for the week * hourly rate).

Implement a function called printDetails() to print the grade, hours worked, and the weekly salary of the employee. Function prototype is given below.

void printDetails(int grade, float hrsWorked, float salary);

In your main function, input the grade and the total number of hours worked during the week from the keyboard. Call printDetails() function and display the details.

Solution



[4]   Version Delta

Unit price of three items are listed below.

Item Unit price(Rs)
1 100.00
2 200.00
3 300.00

Implement a function called totalCost() to find and return the total cost. Item number and the quantity purchased from that item should be entered as parameters. Function prototype is given below.

calculateTotalCost(int itemNo, int quantity);
(Total cost = unit price * quantity).

Implement a function called printDetails() to print the item number, quantity, and the total cost. Function prototype is given below.

void printDetails(int itemNo, int quantity, float totalCost);

In your main function, input item number and the quantity purchased from the keyboard. Call printDetails() function and display the details.

Solution



Assessment 5 – Arrays

[1]   Version Alpha

A company wants their customers to rate their services on a scale of 1 to 5. They wish to store the number of responces from their customers using an array. Array element 0 store the number of responses for 1, array element 1 store the rating for 2 and so on. Write a C program to do the following:
(a) Declare an one dimensional array called rate of size 5.
(b) Initialize all the array elements to zero.
(c) Read the ratings(number from 1 to 5) from the keyboard and store responses for each rate in the array. You should read the responces 5 times.

If the user input a number less than 1 or greater than 5, display an appropriate error message.

Input format:

Please enter your rating: 4
Please enter your rating: 3
Please enter your rating: 5
Please enter your rating: 1
Please enter your rating: 3

(d) Display the number of responses for each rating as follows.

Rating   Number of responses
1                       1
2                       0
3                       2
4                       1
5                       1

Solution



[2]   Version Bravo

An aptitude test of a particular university will take 10 applicants at a time. Those who scored more than the average mark will be qualified to enter the university. Others have to take the test again. Write a C program to enter marks in an array and find the marks which will be qualified.

(a) Declare an integer array called testMarks of size 10.
(b) Initialize all the array elements to -1.
(c) Read the marks from keyboard and store then in the array.

If the input a mark less than 0 or grater than 100, display an appropriate error message and ask to re-enter the mark.

Input format:

Input mark 1: 92
Input mark 2: 110
Invalid mark. Please re-enter.
Input mark 2: 76
....................................
....................................
Input mark 10: 84

(d) Display the marks which will be qualified.

Exaxmple:

Input array:
92 76 80 48 66 89 61 56 92 84
Output:
Passed marks: 92 76 80 89 92 84

Solution



[3]   Version Charlie

An aptitude test of a particular university will take 10 applicants at a time. Those who scored more than the average mark will be qualified to enter the university. Others have to take the test again. Write a C program to enter marks in an array and find how many applicants have failed the test.

(a) Declare an integer array called marks of size 10.
(b) Initialize all the array elements to -1.
(c) Read the marks from keyboard and store then in the array.

If the input a mark less than 0 or grater than 100, display an appropriate error message and ask to re-enter the mark.

Input format:

Input mark 1: 92
Input mark 2: 110
Invalid mark. Please re-enter.
Input mark 2: 76
....................................
....................................
Input mark 10: 84

(d) Display the number of failed candidates.

Example:

Input array:
92 76 80 48 66 89 61 56 92 84
Output:
Number of failed applicants: 4

Solution



[4]   Version Delta

A company uses an array to store the salaries of their employees.
Write a C program to do the following.

(a) Declare a double array called salaries of size 5.
(b) Initialize all the array elements to -1.
(c) Input the salaries of 5 employees from the keyboard and store them in the array. If the user input a negative value, display an error message and ask to re-enter the salary.

Input format:

Input salary of employee 1: 20000.00
Input salary of employee 2: 15000.00
Input salary of employee 3: -1200
Please re-enter the amount.
Input salary of employee 3: 75000.00
...................................
...................................

(d) The company decided to give a 10% increment for the employees whose salaries are below 10000.00. Update the array accordingly.
(e) Display the employee number and the new salaries in the following format.

Employee number      Salary
1                xxxxxx
2                xxxxxx

Solution



2 Comments Add yours

  1. Great post, I just ran across your site and wanted to say that I’ve truly enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again very soon!

    Like

  2. Ahamed S.S says:

    Nice, just wanted to say thank you!
    Helped me lot to do such questions like above.
    Just need more solved programs…related to SLIIT syllabus.

    Liked by 1 person

Leave a comment