Question

In: Computer Science

Hello! *Need in C language also need full documentation/explanation of each line* Designing and implementing an...

Hello!
*Need in C language also need full documentation/explanation of each line*

Designing and implementing an Array of Structures - Course Grade
Write a program that uses a structure to store the following data:
Member Name Description
Name Student name
Idnum Student ID number
Scores [NUM_TESTS] an array of test scores
Average Average test score
Grade Course grade
Declare a global const directly above the struct declaration
const int NUM_TESTS = 4; //a global constant
The program should ask the user how many students there are and should then dynamically allocate an array of structures.
The Student struct includes a fixed size scores array to store a list of four test scores for a group of students .
After the array of struct has been dynamically allocated, the program should ask for the name, ID number and four test scores for each student. The average test score should be calculated and stored in the average member of each structure.
The course grade should be computed on the basis of the following grading scale:
Average Test Grade Course Grade
91–100 A
81-90 B
71-80 C
61-70 D
60 or below F
The course grade should then be stored in the Grade member of each structure.
Once all this data is calculated, a table should be displayed on the screen listing each student’s name, ID number, average test score, and course grade.
Input Validation: Be sure all the data for each student is entered. Do not accept negative numbers for any test score.
A sample test run using the Code::Block IDE-Compiler
How many students? 3

Student name: Sandy Shell
ID Number: 12345
Test # 1: 100
Test # 2: 56
Test # 3: 78
Test # 4: 66
Student name: Timothy Moriarty
ID Number: 23456
Test # 1: 90
Test # 2: 78
Test # 3: 45
Test # 4: 56
Student name: Joice Smith
ID Number: 54321
Test # 1: 100
Test # 2: 98
Test # 3: 67
Test # 4: 75

===========================
Course Grade Report
===========================
Student name: Sandy Shell
ID number: 12345
Average test score: 75.0
Grade: C

Student name: Timothy Moriarty
ID number: 23456
Average test score: 67.2
Grade: D

Student name: Joice Smith
ID number: 54321
Average test score: 85.0
Grade: B


Process returned 0 (0x0) execution time : 94.219 s
Press any key to continue.
Please make sure to declare the global constant and your struct above any function prototypes and include appropriate function documentation as needed.
Here is a sample of function prototypes that you may consider implementing...
// Function prototypes
Student *initArrays(int);
void getInfo(Student [], int);
void showInfo(Student [], int);
You may use pointers or constant reference parameters when passing the structure to the functions mentioned above.
*EXTRA CREDIT COMPONENT FOR ASSIGNMENT#7 (5 points) - Select only one and insert as a multiline comment in your source code submitted.
1. How would you modify the program that you wrote for Programming Challenge 7a (monthly budget) so it defines an enumerated data type with enumerators for the months (JANUARY, FEBRUARY, so on). Provide a code snippet on how the program may use the enumerated type to step through each months expense and budget comparison for a full year.
or
2. How would you modify the program that you wrote for Programming Challenge 7b (course grades) so it defines struct member scores as a pointer to an array of test scores. What additional program statements will be needed so that each structure’s score member should point to a dynamically allocated array that will hold the test scores.

Solutions

Expert Solution

#include <stdio.h>

//declaring global constant
const int NUM_TESTS = 4;
//declare a global structure
struct Grade{
//declaring variables
char name[50];
int id;
int scores[4];
float average;
char grade;
};
//declaration of the function get info
void getInfo(struct Grade *g,int n);
//declaration of the function show info
void showInfo(struct Grade *g,int n);
//main function
int main()
{
int n,i,j;
//getting number of students
printf("How many Students? ");
scanf("%d",&n);
//declaring array of structures
struct Grade g[n];
//input values for array of structures
for(i=0;i<n;i++){
printf("Name: ");
//That space in front of % is very important to get space
//separated string input without skipping of input
// if you leave the space in front of % it will skip the input command
scanf(" %[^\n]s",&g[i].name);
printf("Id: ");
scanf("%d",&g[i].id);
for(j=0;j<NUM_TESTS;j++){
printf("Test #%d: ",j+1);
scanf("%d",&g[i].scores[j]);
}
printf("\n");
}
//calling get info method
getInfo(g,n);
printf("---------------------------\n");
printf("---------------------------\n");
printf(" Course Grade Report \n");
printf("---------------------------\n");
printf("---------------------------\n");
//calling show info method
showInfo(g,n);
return 0;
}
//function for getting and calculation of values
void getInfo(struct Grade *g,int n){
int i,j;
//calculating average
for(i=0;i<n;i++){
int sum=0;
for(j=0;j<NUM_TESTS;j++){
sum = sum+g[i].scores[j];
}
g[i].average= sum/NUM_TESTS;
//calculating grades
if (g[i].average>90){
g[i].grade = 'A';
}
else if(g[i].average>80){
g[i].grade = 'B';
}
else if(g[i].average>70){
g[i].grade = 'C';
}
else if(g[i].average>60){
g[i].grade = 'D';
}else{
g[i].grade = 'F';
}
}
}
//function to print structure elements
void showInfo(struct Grade *g,int n){
int i;
//printing array if structure values
for(int i=0;i<n;i++){
printf("Student Name: %s\n",g[i].name);
printf("Student id: %d\n",g[i].id);
printf("Average Test Score: %.1f\n",g[i].average);
printf("Grade %c\n",g[i].grade);
printf("\n");
}
}


Related Solutions

*Need in C language also need full documentation/explanation of each line* Thank you! Write a program...
*Need in C language also need full documentation/explanation of each line* Thank you! Write a program that records high-score data from a simulated FIFA soccer game available online. The program will ask the user to enter the number of scores, create two dynamic arrays sized accordingly, ask the user to enter the indicated number of names and scores, and then print the names and scores sorted by score in descending order. The output from your program should look exactly like...
I need full answer with full details and explanation : The ET students at SWOSU are...
I need full answer with full details and explanation : The ET students at SWOSU are launching a business manufacturing homework-completing robots. There are roughly $253.22 in material costs for each robot (including waste), and the hope is to sell them at the bargain price of $399.99 each. Since they're using the facilities in the ET department, they aren't planning to purchase equipment until after they graduate (2 years from now). They expect to sell 23 robots each quarter until...
Implementing a Naïve Bayes classifier on below data : Please provide full explanation CustID Gender SeniorCitizen...
Implementing a Naïve Bayes classifier on below data : Please provide full explanation CustID Gender SeniorCitizen Married AnyDependents NoOfYrsCustomer PhoneService MultipleLines InternetService OnlineSecurity OnlineBackup DeviceProtection TechSupport StreamingTV StreamingMovies ContractType PaperlessBilling PaymentMethod MonthlyCharges TotalCharges SwitchToCompetitor 1 F 0 Y N 1 N No phone DSL N Y N N N N Monthly Y Electronic check 29.85 29.85 No 2 M 0 N N 34 Y N DSL Y N Y N N N One year N Mailed check 56.95 1889.5 No...
Designing and implementing a C++ structure data type - Monthly Budget Remember to use correct code...
Designing and implementing a C++ structure data type - Monthly Budget Remember to use correct code formatting and documentation. A student has established the following monthly budget: Budget Categories       Budgeted amount ----------------------------------------------------- Housing                  $ 580.00 Utilities                   $ 150.00 Household Expenses    $ 65.00 Transportation           $ 50.00 Food                      $ 250.00 Medical                  $ 30.00 Insurance                $ 100.00 Entertainment           $ 150.00 Clothing                  $ 75.00 Miscellaneous           $ 50.00 ---------------------------------------------------- Write a program that declares a MonthlyBudget structure designed with member variables to hold each of these expense categories. The program should define two MonthlyBudget structure variables...
Hello this is for C++ language. I am currently stuck on creating my api for Day...
Hello this is for C++ language. I am currently stuck on creating my api for Day Trading Stocks. as follows I need an api for *//Function Signature * * parameter: * * Return Value: ** *// Write the following function taking in an integer vector (vector &prices) consisting of all prices, in chronological order, for an hypothetical instrument. Your function recommends the maximum profit an investor can make by placing AT MOST one buy and one sell order in the...
in C programming language char character [100] = "hello"; a string array variable It is given....
in C programming language char character [100] = "hello"; a string array variable It is given. By writing a function called TranslateString, By accessing the pointer address of this given string, returning the string's address (pointer address) by reversing the string Write the function and use it on the main function. Function void will not be written as. Return value pointer address it will be. Sweat operation on the same variable (character) It will be made. Declaration of the function...
I need a full explanation of - Types of Road maintenance and tools Please include at...
I need a full explanation of - Types of Road maintenance and tools Please include at least 2 references,thanks.
Hello, I need a simple financial explanation for the below sentence: Cash flows into MFs investing...
Hello, I need a simple financial explanation for the below sentence: Cash flows into MFs investing in stocks are highly correlated with the return on stock markets
C++ good documentation as well as explanations would be great. I need the code to be...
C++ good documentation as well as explanations would be great. I need the code to be written without (#include if possible. Please don't just copy and paste someone else's answer. In this HW assignment we will simulate a car wash and calculate the arrival time, departure time and wait time for each car that came in for a car wash. We will use the following assumptions about our car wash: Each car takes 3 minutes from start of the car...
C++ Hello .I need to convert this code into template and then test the template with...
C++ Hello .I need to convert this code into template and then test the template with dynamic array of strings also if you can help me move the function out of the class that would be great.also There is a bug where the memory was being freed without using new operator. I cant seem to find it thanks in advance #include using namespace std; class DynamicStringArray {    private:        string *dynamicArray;        int size;    public:   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT