// Program to generate report-format for Student data using structures. // Assignment-14 // stustrrep.cpp, Author - Krishna Kumar Khatri. // Uncomment ONLY the following line if you are using Turbo/Borland compiler. // #define TC #ifdef TC #include #include #else #include #include using namespace std; #endif #include // For getch. const int MAXLEN = 50; struct Student { long int rollno; char name[MAXLEN]; char branch[MAXLEN/2]; float obtndmarks; }; void read_data(Student& st) { char tmpstr[MAXLEN]; cout << "\nRoll no.: "; cin >> st.rollno; cout << flush; // Emptying buffer. cout << "Name: "; cin.get(st.name, MAXLEN); cout << flush; // Emptying buffer. cout << "Branch: "; cin.get(st.branch, MAXLEN / 2); cout << flush; // Emptying buffer. cout << "Marks(%): "; cin >> st.obtndmarks; } void display_report(Student st[], const int& size) { int i; cout << endl << "REPORT" << endl; cout << "======" << endl; cout << "Roll no Name Branch Marks(%)\n"; cout << "------- ------------------- ------------- --------\n"; for (i = 0; i < size; i++) { cout << setw(7) << setiosflags(ios::left) << st[i].rollno << " "; cout << setw(19) << st[i].name << " "; cout << setw(13) << st[i].branch << " "; cout << st[i].obtndmarks << endl; } } int main() { #ifdef TC clrscr(); #endif Student* st; int n, i; do { cout << "How many students (1-" << MAXLEN / 5 << "): "; cin >> n; } while (n < 1 || n > MAXLEN / 5); st = new Student[n]; for (i = 0; i < n; i++) read_data(st[i]); display_report(st, n); cout << endl << endl << "Program over. Press any key to exit..."; getch(); return 0; // Successful termination. }