In: Computer Science
You will be writing the function definition and the main function with the function call.
Be sure to write the function definition below the main function.
The function prototype has been provided, you may add the prototype to you answer.
You do not need to add the preprocessor directives like #include<stdio.h>.
Write the function definition for UpdateGrade . The function will take two arguments, a double called originalGrade a pointer to a double called newGradePtr.
This function will have a void return type.
Inside the UpdateGrade function:
In the main function
#include<stdio.h>
//function prototypes
void UpdateGrade(double originalGrade, double *newGradePtr);
in C programming language
Only Function Definition is given below:
(Explanation is given in the form of comments)
//Function Definition
void UpdateGrade(double originalGrade, double *newGradePtr){
// variable declared ask
double ask;
//taken input from the user to add number of points to be added
in original grade
printf("\nEnter the number of points to be added to the original
grade:");
scanf("%lf",&ask);
//upgraded the value of the variable whose address is stored in
newGradePtr
*newGradePtr = ask + originalGrade;
}
--------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------
Complete Program (is given below) :
-------------------------------------------------------------------------------------------------------
void UpdateGrade(double originalGrade, double *newGradePtr);
int main(){
//two local variables declared i.e. grade and updatedGrade
double grade, updatedGrade;
// taken input from the user
printf("Enter the original grade:");
scanf("%lf",&grade);
//called the function UpdateGrade and passed the arguments
//first argument is grade
//second argument is updatedGrade and its address is passed
UpdateGrade(grade,&updatedGrade);
//below statement prints the updated grade
printf("\nThe updatedGrade is %lf",updatedGrade);
return 0;
}
//Function Definition
void UpdateGrade(double originalGrade, double *newGradePtr){
// variable declared ask
double ask;
//taken input from the user to add number of points to be added
in original grade
printf("\nEnter the number of points to be added to the original
grade:");
scanf("%lf",&ask);
//upgraded the value of the variable whose address is stored in
newGradePtr
*newGradePtr = ask + originalGrade;
}
-------------------------------------------------------------------------------------------------------------------------
Sample Output: