nie-ii-year

lab stuff from undergrad second year.
git clone http://git.hanabi.in/repos/nie-ii-year.git
Log | Files | Refs | LICENSE

stud.cpp (1338B)


      1 #include <iostream>
      2 #include <stdlib.h>
      3 // using namespace std;
      4 
      5 class STUDENT {
      6   char name[20];
      7   char USN [11];
      8   int marks[3];
      9   float average;
     10 public:
     11   void input(void);
     12   void output(void);
     13   void calcAverage(void);
     14 };
     15 // int min(int, int);
     16 
     17 int main() {
     18   int size;
     19   do{
     20     std::cout << "\nEnter number of students: ";
     21     std::cin >> size;
     22     if(size < 1)
     23       std::cout << "\nInvalid size, try again.\n";
     24   } while (size < 1);
     25   STUDENT  *s = (STUDENT*)malloc(sizeof(STUDENT) * size);
     26   if(!s) {
     27     std::cout << "\nInsufficient memory.\n";
     28     return 0;
     29   }
     30   std::cout << "\nEnter the name, USN, and marks of three tests.\n";
     31   for(int i = 0; i < size; i++)
     32     (*(s + i)).input();
     33   std::cout << "\nThe name, USN, and marks of the students are:\n";
     34   for(int i = 0; i < size; i++)
     35     (*(s + i)).output();
     36   return 0;
     37 }
     38 
     39 int min (int x, int y){
     40   return (x > y ? y : x);
     41 }
     42 
     43 void STUDENT::calcAverage(void) {
     44   average = marks[0] + marks [1] + marks[2] - min(marks[0], min(marks[1], marks[2]));
     45   average/=2;
     46 }
     47 
     48 void STUDENT::input(void) {
     49   std::cin >> name >> USN >> marks[0] >> marks[1] >> marks[2];
     50   calcAverage();
     51 }
     52 
     53 void STUDENT::output(void) {
     54   std::cout << std::endl << "Name: " << name << std::endl << "USN: " << USN << std::endl << "Average: " << average << std::endl << "====================" << std::endl;
     55 }