CS36 C Programming Homework 5 20 Points (Lesson 1 To Lesson 61)
CS36 C Programming Homework 5 20 Points (Lesson 1 To Lesson 61)
1. You must turn in your program listing and output for each program set. Each program set must have
your student name, student ID, and program set number/description. Late homework will not be
accepted for whatever reasons you may have.
*********for this homework, you are to submit your Program sets to Canvas under Homework 5 link*********
a. Name your files: HW5_PS1_ lastname_firstinitial.c for Program Set 1 and HW5_PS2_
lastname_firstinitial.c for PS2 and so on. PS means program set. If there are two program sets
you will submit two files one for each program set. Example if your name is Joe Smith then the
filename will be HW5_PS1_smith_j.c
b. You must submit your homework by the deadline at the specified upload link on Canvas under
homework 5. Homework submitted via email attachment, comment in Canvas, Canvas message,
or by any other method is not accepted and will be given a zero for no submission.
c. if you do not follow instructions on file naming provided in this section you will receive a zero for
the question you did not correctly name the file.
2. Please format you output properly, for example all dollar amounts should be printed with 2 decimal
places when specified. Make sure that your output values are correct (check the calculations).
3. Use only the 'tools' in the topics we covered up till lesson 61 only. A zero grade will be given if any
topics not covered from lesson 1 to lesson 61 is used in each of your program set.
Each student is expected to do their own work. IF IDENTICAL PROGRAMS ARE SUBMITTED, EACH
IDENTICAL PROGRAM WILL RECEIVE A SCORE OF ZERO.
Grading:
If a program does not compile the program set will receive a zero score. If the program compiles and run
but does not have proper declaration of variables, syntax, logic, and displays the correct output (given in
the sample test runs) with proper formatting as specified in the question, the program set will receive a
zero score. Each program set must compile and must run correctly with proper declaration of variables,
syntactically, logically, and display the correct output (given in the sample test runs) as specified then
you will receive the full points for that question. Then points will be deducted for not having proper:
d. Use only 'tools' in the topics that have been covered in class (lesson 1 to lesson 61)
e. Output (you must provide the specified number of test runs or your program set will receive a
zero score)
- to be displayed at the end of the program listing(codes) and commented
- must have the number of test runs as specified in each program set.
- must use the data for test runs when they are provided for you in the question.
Points will be deducted from items a. to d. above until your Program Set reaches zero points.
NO GLOBAL VARIABLES ALLOWED and you must use function prototype for
this homework 5. The break, continue and goto C commands are not allowed to
be used. A zero will be given for the program set if your program contains a
global variable, break, continue or goto command. The break command is
allowed only as part of the switch statement.
Program Set 1
Write a C program to calculate salary raise for employees which uses the following functions for an array of
structures for 6 employees. You must use functions for this program set as described in class lecture.
1. Allow the user to enter the employee name and salary for each employee and for each employee
calculate the raise, and the new salary with the raise into an array of structures.
2. Sort the array of structures on name and print the array after the sort is completed.
3. Calculate and print the total Salary, total raises, and total new salary.
4. Save the array of structures to a text file.
5. Retrieve and print the text file.
6. Save the array of structures to a binary file.
7. Retrieve and print the binary file.
Your Test run output should look like this sample(User input in red)
Here is the template for your program. You must use this template for your program and you are not allowed to
change any codes inside the template. Write codes for those in red. You only need one test run for all 6 employees.
(download the hw5template.c and use it for your program)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 6
struct Employee
{
//declare your struct data members here
};
int main()
{
//declaration of variables
struct Employee e[SIZE];
float ts, tr, tn;
//load data into struct, calculate raises, salaries and new salaries and print the
//original array of struct
load(e, SIZE);
ARate(e, SIZE);
calcRaise(e, SIZE);
total(e, SIZE, &ts, &tr, &tn);
printf("Original Array of Structure before Sorting\n\n");
title();
print(e, SIZE);
printTotals(ts, tr, tn);
//sort the struct of array and print the sorted struct of array
sort(e, SIZE);
total(e, SIZE, &ts, &tr, &tn);
printf("Array of Structure after Sorting\n\n");
title();
print(e, SIZE);
printTotals(ts, tr, tn);
return 0;
{
//assign each employee rate to the struct’s rate data member here by checking salary //range
//for example
// if(e[i].sal >= 0.00 && e[i].sal < 30000.00)
// e[i].rate = 7.00;
void total(struct Employee e[], int n, float *ts, float *tr, float *tn )
{
//ts = total salary(sum the salaries of all 6 employees)
//tr = total raise(sum the raises of all 6 employees)
//tn = total new salary(sum of new salaries of all 6 employees)
}
void title()
{
{
//retrieve the data from employees.txt file
}