Description
-
(45 Pts) Write a complete C program for “Guessing An Integer Number” game. Your program should be as follow
– Generates a random number between 1 to 10 (name the variable as “number”)
– Player has 2 chances to guess (name the variable as guess; each time only one guess should be entered)
– Checking a guess
– If it is smaller or greater than the number
– Calculate the absolute of the difference between the guess and the number
– If the difference is greater than or equal to 5 of the number
– Program should warn the player as “You are too far from the number”
– If the difference is greater than or equal to 3 of the number
– Program should warn the player as “You are far from the number”
– If the difference is smaller than or equal to 2 of the number
– Program should warn the player as “You are close to the number”
– If it is equal to the number print a congratulation for winning.
Your program should contain at least 3 functions
– RNG : To generate the random number
– CalculateTheDifference : To calculate the difference between guess and the number
– WarnThePlayer : To print a warning in order to guide the player.
Hint: 1. Use rand() function to generate a random number that is declared in “stdlib.h”.
-
-
Each time when the player enter her/his guess update the guess variable.
-
– Your program should take student information from an input file called “Students.txt”. The input file contains 2 initials (for Name and Surname) and 3 integers (Midterm1 Midterm2 Final).
– Midterms has a weight of 30% and Final has a weight of 40%. You are supposed to write a function that calculates and returns the resulting grade as integer.
– Using if statement assign the corresponding letter grade and (using the information in the table below)
– Write a function takes the grade for a student as input; using switch statement calculates the contribution of the resulting grade to the GPA and prints it to the screen; Assume that each student takes 20 credits in the current term and the course has 3 credits(e.g. assume a student has a grade “A”, therefore, 4 credit; the contribution is 4*3/20)
– Write the results with the initials to an output file called “Grades.txt”.
-
Point
Grade
Credit
85-100
A
4
70-84
B
3
65-69
C
2
40-64
D
1
39 and lower
F
0
The format of the input file ‘Students.txt’ will be as follows:
-
-
Student Name 1> < Student Surname 1 > < Midterm1 Point 1> < Midterm2 Point 1> < Final Point 1>
-
-
Student Name 2> < Student Surname 2 > < Midterm1 Point 2> < Midterm2 Point 2> < Final Point 2>
The format of the output file ‘Grades.txt’ will be as follows:
-
Student Name 1> < Student Surname 1> < Grade 1 > < Contribution 1 >
-
Student Name 2> < Student Surname 2> < Grade 2 >< Contribution 2 >
An example of inputs and outputs are shown below:
Content of ‘Students.txt’:
BT 30 40 50
ES 90 80 90
Content of ‘Grades.txt’:
BT 41
ES 87
-
Obey honor code principles.
-
Read your homework carefully and follow the directives about the I/O format (data file names, file formats, etc.) and submission format strictly. Violating any of these directives will be penalized.
-
Obey coding convention.
-
Your submission should include the following files and NOTHING MORE (no data files, object files, etc):
HW02_<student_name>_<studentSirname>_<student number>_part1.c HW02_<student_name>_<studentSirname>_<student number>_part2.c
-
Do not use non-English characters in any part of your homework (in body, file name, etc.).
-
Deliver the printout of your work until the last submission date.