[Solved] CS 1050: Homework Assignment 3

$25

File Name: CS_1050:_Homework_Assignment_3.zip
File Size: 282.6 KB

SKU: [Solved] CS 1050: Homework Assignment 3 Category: Tag:
5/5 - (1 vote)

CS 1050Homework Assignment 3

DirectionsComplete the following homework assignment using the description given in each section.Purpose? Use command line arguments to read input from the user.? Use rand() and srand() functions from the library to generate random numbers.? Use malloc function to allocate memory and create arrays.? Use pointers arithmetic and notation in implementation.Submission informationSubmit this assignment on the blackboard using the link provided under the section assignments(submit HW3). SUBMIT ONLY the .C file. All the HW assignment must be submitted by the duedate on the blackboard.DescriptionThe homework assignment is on students grades in a class. There are n students in the class. Thenumber n is read from the command prompt (similar to prelab-7 and lab-7). Each student have astudent id which is a random number between 900-999. There are three courses and students havescores for each of the three courses. The score in a course is a random number between 50-100.Here assume that the lowest score is going to be 50. For the assignment you have to create astudent id array (int) and three (int) arrays for students scores in the three courses. A randomnumber between 50-100 can be created by first dividing the number by 51 and then adding 50 toit similarly random number 900-999 can be generated. Using the rand() function initialize thestudent id array and course score arrays with random numbers (same as previous labs). Once thisis set up you have to use this information to perform various operations like compute the grade ofeach student, median score for each course, search student grade etc.Command Line argumentsAs explained above the total number of student in class is read from the command prompt(similar to prelab-7 (and lab 7)) . User is going the provide the input from the command line inthe following./a.out 10Here 10 is the size of the class and will be stored in the argv array as string so you need to convertthis string number 10 to integer number 10. To convert string to integer make use of functionatoi (as shown in the example below). The variable size contains an integer number which can beused making the function calls. For more detail on command line refer to prelab 7.int main(int argc , char **argv){if(argc<2){printf(
Not enough parameters
);return 0;}int size =atoi(argv[1]);…}Implement following functions for the homework assignment.int* create_id(int)- This function takes an integer number (size) and use it to create an integerarray using malloc function. Once the array is created store a random number between 900-999 inthe integer array. While generating the student id make sure that none of the student id repeatedso if the size is 10 then there should be 10 unique id (between 900-999) stored in the integerarray. Your function should correctly implement this logic. At the end return the integer pointer.int* create_score(int)- This function similar to create_id function takes an integer number(size) and use it to create an integer array using malloc function. Once the array is created store arandom number between 50-100 in the integer array. At the end return the integer pointer.

float* average_score(int*, int*, int*, int)- This function takes the scores in three coursesand the size and calculates the average score for each student. The average score is stored in afloat array which is created by using a malloc function. At the end it return the pointer to a floatarray.char *calculate_grade(float*, int)- This function takes the average score of students in threecourses and the size and calculates the students grade using the criteria below. It stores the studentgrade in a character array which is again created by using a malloc function. At the end it returnsthe pointer to character array.Use following grading criterion to calculate the students grade in the course.average score> =90 Abetween 80-89 Bbetween 70-79 Cbetween 60-69 Dbelow 60 Ffloat median(int*, int)- This function takes an integer pointer (scores in a course) and size andcalculate the median score in the course. At the end it returns the median value(float).Median: Median is the value located in the middle for a given set of numbers. To compute themedian first sort the numbers and then select the middle value as a median. The numbers in agiven set can be even or odd median value can be calculated for both such cases as shown in theexample below.For odd size inputx={2,4,1,0,9}sorted x={0,1,2,4,9}median value is 2For even size inputx= {2, 5, 0, 9}sorted x={0, 2 ,5, 9}median =(2+5)/2=3.5void print_scorecard( int*, int*, int*, int*, float*, char*, int)- This function takes studentid array , student score arrays, average score array , letter grade array and print the information asshown in the sample output below.int search_id(int *, int, int)- This functions takes the student id array, its size and an id that needto be searched in the student id array if the id is present then it returns the index of the idotherwise it returns -1.void histogram(char *, int)- This functions takes grade array and size and display thehistogram of grades as shown in the sample output below.main(): In the main first perform an error check using argc variable to make sure that user hasentered all the inputs from the command prompt if not display an error message and quit theprogram (see the prelab 7 document for more detail). As shown above use atoi function to converta string to an integer number. To use this function include stdlib.h file in the code. Call create_idand create_score functions using this size to create student id, course score arrays. Callaverage_score and calculate_grade functions to calculate the average score and students grade.Call function print_scorecard to display the result as shown in the sample output below.Note:1. Similar to prelab-7 and lab-7 use malloc function to allocate space to the pointer.2. Like the prelab-7 and lab-7 use POINTER NOTATION AND POINTER ARITHMETIConly to implement the homework assignment.Sample Output[[email protected] HW3]$ ./a.outNot enough arguments[[email protected] HW3]$ ./a.out 10ID Course1 Course2 Course3 Average Grade973 53 59 90 67.33 D914 66 51 57 58.00 F923 85 78 74 79.00 C911 77 57 100 78.00 C952 54 98 85 79.00 C932 85 67 66 72.67 C935 51 53 67 57.00 F984 78 57 99 78.00 C916 90 88 72 83.33 B908 79 91 70 80.00 BEnter the student id to search:908The student with id 908 has the following scoresCourse1:79Course2:91Course3:70Average score:80.00Grade BMedian score for course1 is 77.50Median score for course2 is 63.00Median score for course3 is 73.00Grade HistogramA:B:**C:*****D:*E:F:**[[email protected] HW3]$ ./a.out 9ID Course1 Course2 Course3 Average Grade906 82 86 94 87.33 B992 57 69 71 65.67 D939 50 84 54 62.67 D965 88 52 89 76.33 C997 86 80 68 78.00 C943 98 76 94 89.33 B923 59 98 54 70.33 C946 51 77 82 70.00 C948 60 80 74 71.33 CEnter the student id to search:933The student id 933 is not present.Median score for course1 is 60.00Median score for course2 is 80.00Median score for course3 is 74.00Grade HistogramA:B:**C:*****D:**E:F:Guidelines for Grading HW-340 Points PossibleGeneralIf your program does not compile, or produce any input/output (I/O) becausemost of the source code is commented out then your HW will receive a grade ofNO POINTS. For any partial credit your C program must not only compile but alsoproduce some valid I/O that meets HW specifications. Use pointers and pointernotation in implementation. Use of array notation will be given zero.-5 points Not having proper format.5 points Reading size correctly from the command prompt and performing anerror check using command line arguments5 points Initializing the three arrays correctly with random numbers.5 points Calculating the average score correctly.5 points Calculating the grade correctly.5 points Implementing search_id function correctly.7 points Printing information correctly using print_scorecard function.8 points Printing the grade histogram correctly.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS 1050: Homework Assignment 3
$25