forked from waboke/solutions_to_pastquestions_2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudentmetadata.cpp
54 lines (43 loc) · 1.48 KB
/
studentmetadata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cstring> // For string operations
using namespace std;
// Define the Student structure
struct Student {
char name[50];
int age;
float totalMarks;
};
// Function to input data for a student
void inputStudentData(Student* student) {
cout << "Enter name: ";
cin.ignore(); // Ignore newline left in the input buffer
cin.getline(student->name, 50);
cout << "Enter age: ";
cin >> student->age;
cout << "Enter total marks: ";
cin >> student->totalMarks;
}
// Function to display student information
void displayStudentData(const Student* student) {
cout << "Name: " << student->name << endl;
cout << "Age: " << student->age << endl;
cout << "Total Marks: " << student->totalMarks << endl;
}
// Function to calculate average marks of two students
float calculateAverageMarks(const Student* student1, const Student* student2) {
return (student1->totalMarks + student2->totalMarks) / 2.0;
}
int main() {
Student student1, student2;
cout << "Enter data for Student 1:" << endl;
inputStudentData(&student1);
cout << "\nEnter data for Student 2:" << endl;
inputStudentData(&student2);
cout << "\nStudent 1 Details:" << endl;
displayStudentData(&student1);
cout << "\nStudent 2 Details:" << endl;
displayStudentData(&student2);
float averageMarks = calculateAverageMarks(&student1, &student2);
cout << "\nThe average marks of the two students are: " << averageMarks << endl;
return 0;
}