Last active
November 6, 2019 01:15
-
-
Save TokisakiKurumi2001/60dbe3131e67e0322f922bfae110b69c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string.h> | |
| #include <iomanip> | |
| using namespace std; | |
| const int MAX = 100; | |
| struct student | |
| { | |
| char name[20]; | |
| long rollno; | |
| char sex; | |
| float height; | |
| float weight; | |
| }; | |
| int main(int argc, const char * argv[]) | |
| { | |
| student cls[MAX]; | |
| int i, n, max; | |
| float avg_height_f, avg_weight_f; | |
| printf("Please enter the number of students: "); | |
| cin >> n; | |
| max = (MAX > n) ? n : MAX; | |
| avg_height_f = 0; | |
| avg_weight_f = 0; | |
| for (i = 0; i < max; i++) { | |
| printf("Record %d\n", i+1); | |
| printf("Name: "); | |
| cin >> cls[i].name; | |
| printf("Rollno: "); | |
| cin >> cls[i].rollno; | |
| printf("Sex: "); | |
| cin >> cls[i].sex; | |
| printf("Height: "); | |
| cin >> cls[i].height; | |
| printf("Weight: "); | |
| cin >> cls[i].weight; | |
| printf("\n"); | |
| } | |
| cout << left << setw(25) << "Name" << setw(15) << "Rollno" << setw(5) << "Sex" << setw(10) << "Height" << setw(10) << "Weight" << endl; | |
| for (i = 0; i < n; i++) { | |
| cout << left << setw(25) << cls[i].name << setw(15) << cls[i].rollno << setw(5) << cls[i].sex << setw(10) << cls[i].height << setw(10) << cls[i].weight << endl; | |
| } | |
| for(i = 0; i < max; i++) | |
| { | |
| avg_height_f += cls[i].height / max; | |
| avg_weight_f += cls[i].weight / max; | |
| } | |
| printf("\nThe average height is : %f\n", avg_height_f); | |
| printf("The average weight is : %f\n", avg_weight_f); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment