Created
September 8, 2019 17:41
-
-
Save andraantariksa/37d9023301d0250398d87deb46fd344b to your computer and use it in GitHub Desktop.
Student
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 <string> | |
#include <cstdlib> | |
#include <cstdio> | |
#include <iostream> | |
struct student { | |
int id; | |
std::string name; | |
int age; | |
char gender; | |
float gpa; | |
}; | |
int main() | |
{ | |
unsigned int student_total; | |
student *students; | |
std::cin >> student_total >> std::ws; | |
students = (student*) malloc(sizeof(student) * student_total); | |
for(int i = 0; i < student_total; i++) | |
{ | |
student student_temp; | |
std::cin >> student_temp.id >> std::ws; | |
std::getline(std::cin, student_temp.name); | |
std::cin >> student_temp.age >> std::ws; | |
std::cin >> student_temp.gender >> std::ws; | |
std::cin >> student_temp.gpa >> std::ws; | |
*(students + i) = student_temp; | |
} | |
printf("%-3s %-10s %-3s %-6s %-3s\n", "ID", "Name", "Age", "Gender", "GPA"); | |
for(int i = 0; i < student_total; i++) | |
{ | |
printf("%-03d %-10s %-3d %-6c %-3.1f\n", (students + i)->id, (&(students + i)->name)->c_str(), (students + i)->age, (students + i)->gender, (students + i)->gpa); | |
} | |
free(students); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment