I need help in solving this programming problem. Thank you! // ********************* MODIFY ME!!! ********************* #include #include #include "lab4_ex1.h" // Removes or cleans the dangling 'new line' character in stdin // @param void // @return none void flush() { char c; while ((c = getchar()) != '\n' && c != EOF); } // Creates the course (one course only) by asking the for user input // @param num course number, e.g. 1,2,3 // @return course Course createCourse(int num) { Course course; //input code here return course; } // Displays the course // @param course number, e.g. 1, 2, 3 // @return none void displayCourse(Course course) { printf("course name: %s\n", course.name); printf("course grade: %0.2f\n", course.grade); printf("course units: %d\n", course.unit); } // Computes the GPA from three courses, based on the formula in README.md // @param courses[TOTAL_COURSE] // @return GPA float computeGPA(Course courses[TOTAL_COURSE]) { // ********************* YOUR CODE HERE ********************* return 0.0f; } // Creates the student by asking for user input // @param none // @return student structure with id, name, degree, courses, and GPA Student createStudent() { Student student; // input code here return student; } // Displays the student // @param student struct // @return none void displayStudent(Student student) { printf("student name: %s\n", student.name); printf("ID number: %d\n", student.id); printf("degree: %s\n", student.degree); for (int i = 0; i < TOTAL_COURSE; i++) { displayCourse(student.courses[i]); } } // Displays the student with GPA // @param student struct // @return none void displayStudentGPA(Student student) { printf("%s with ID number %d has a GPA of %.3f\n", student.name, student.id, student.GPA); } this is the header file // ********************* MODIFY ME!!! ********************* #ifndef lab4_ex1_h #define lab4_ex1_h #define TOTAL_COURSE 3 #define BUFFER_SIZE 80 typedef struct Course{ char name[BUFFER_SIZE]; int unit; float grade; } Course; typedef struct Student{ int id; char name[BUFFER_SIZE]; char degree[BUFFER_SIZE]; Course courses[TOTAL_COURSE]; float GPA; } Student; Student createStudent(); Course createCourse(int); void displayStudent(Student); void displayStudentGPA(Student student); void displayCourse(Course); float computeGPA(Course courses[TOTAL_COURSE]); void flush(); #endif this is the main.cpp file #include // needed by printf, scanf #include // needed by malloc #include "lab4_ex1.h" int main(void) { int N; // Get the number of students N do { printf("Enter number of students to record: "); scanf("%d", &N); } while (N < 1); flush(); // Allocate memory to the data of students Student *record = (Student *)malloc(N * sizeof(Student)); // Create student record/s for (int i = 0; i < N; i++) record[i] = createStudent(); // Display GPA for all student records for (int i = 0; i < N; i++) displayStudentGPA(record[i]); free(record); return 0; }
I need help in solving this programming problem. Thank you!
// ********************* MODIFY ME!!! *********************
#include <stdio.h>
#include <string.h>
#include "lab4_ex1.h"
// Removes or cleans the dangling 'new line' character in stdin
// @param void
// @return none
void flush()
{
char c;
while ((c = getchar()) != '\n' && c != EOF);
}
// Creates the course (one course only) by asking the for user input
// @param num course number, e.g. 1,2,3
// @return course
Course createCourse(int num)
{
Course course;
//input code here
return course;
}
// Displays the course
// @param course number, e.g. 1, 2, 3
// @return none
void displayCourse(Course course)
{
printf("course name: %s\n", course.name);
printf("course grade: %0.2f\n", course.grade);
printf("course units: %d\n", course.unit);
}
// Computes the GPA from three courses, based on the formula in README.md
// @param courses[TOTAL_COURSE]
// @return GPA
float computeGPA(Course courses[TOTAL_COURSE])
{
// ********************* YOUR CODE HERE *********************
return 0.0f;
}
// Creates the student by asking for user input
// @param none
// @return student structure with id, name, degree, courses, and GPA
Student createStudent()
{
Student student;
// input code here
return student;
}
// Displays the student
// @param student struct
// @return none
void displayStudent(Student student)
{
printf("student name: %s\n", student.name);
printf("ID number: %d\n", student.id);
printf("degree: %s\n", student.degree);
for (int i = 0; i < TOTAL_COURSE; i++)
{
displayCourse(student.courses[i]);
}
}
// Displays the student with GPA
// @param student struct
// @return none
void displayStudentGPA(Student student)
{
printf("%s with ID number %d has a GPA of %.3f\n", student.name, student.id, student.GPA);
}
this is the header file
// ********************* MODIFY ME!!! *********************
#ifndef lab4_ex1_h
#define lab4_ex1_h
#define TOTAL_COURSE 3
#define BUFFER_SIZE 80
typedef struct Course{
char name[BUFFER_SIZE];
int unit;
float grade;
} Course;
typedef struct Student{
int id;
char name[BUFFER_SIZE];
char degree[BUFFER_SIZE];
Course courses[TOTAL_COURSE];
float GPA;
} Student;
Student createStudent();
Course createCourse(int);
void displayStudent(Student);
void displayStudentGPA(Student student);
void displayCourse(Course);
float computeGPA(Course courses[TOTAL_COURSE]);
void flush();
#endif
this is the main.cpp file
#include <stdio.h> // needed by printf, scanf
#include <stdlib.h> // needed by malloc
#include "lab4_ex1.h"
int main(void)
{
int N;
// Get the number of students N
do
{
printf("Enter number of students to record: ");
scanf("%d", &N);
} while (N < 1);
flush();
// Allocate memory to the data of students
Student *record = (Student *)malloc(N * sizeof(Student));
// Create student record/s
for (int i = 0; i < N; i++)
record[i] = createStudent();
// Display GPA for all student records
for (int i = 0; i < N; i++)
displayStudentGPA(record[i]);
free(record);
return 0;
}
![Laboratory Activity 4 - Structures
Student Grade Mini-Database
Develop a program that will define and store a student record. The data will be entered by the user. Afterwards,
calculate and display the GPA of each student. You will need to use structure with array.
In case you don't know how to calculate GPA, here's the formula:
Total_Credit_Honors
Total_Units
GPA
Total_Credit_Honors = YTOTAL_COURSE
Grade,*Unit;
-i = 1](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6f4adae0-2fda-4c43-b97b-09c46a19ec3e%2F3100e4e6-b2ba-40ea-a44a-bd503972fd0e%2F0us4tmm_processed.png&w=3840&q=75)
![Sample Console Input
Expected Console Output
Enter number of students to record: 2
student name: John Anthony
ID number: 10912345
degree: ECE
2
John Anthony
10912345
course 1 name: Physics
course 1 grade: 100
ЕСЕ
Physics
100
course 1 total units: 3
3
course 2 name: Mathematics
Mathematics
course 2 grade: 70
70
course 2 total units: 2
course 3 name: Geology
course 3 grade: 50
2
Geology
50
course 3 total units: 1
1
student name: Jose
Jose
ID number: 10854321
degree: CPE
course 1 name: Physics
course 1 grade: 80
10854321
СРЕ
Physics
80
course 1 total units: 3
3
course 2 name: Mathematics
Mathematics
course 2 grade: 60
60
course 2 total units: 2
course 3 name: Geology
course 3 grade: 90
2
Geology
90
course 3 total units: 1
1
John Anthony with ID number 10912345 has a GPA of 81.667
Jose with ID number 10854321 has a GPA of 75.000](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F6f4adae0-2fda-4c43-b97b-09c46a19ec3e%2F3100e4e6-b2ba-40ea-a44a-bd503972fd0e%2F13ves5c_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)