nie-ii-year

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

commit d804059d4ceec67d320bb51fe3d1fd171d765770
parent ba779831c25d84c957ac5763f2cfbf32e99d829e
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Fri, 15 Sep 2017 10:19:56 +0530

another week's assignment
Diffstat:
As3/oops/stud.cpp | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+), 0 deletions(-)

diff --git a/s3/oops/stud.cpp b/s3/oops/stud.cpp @@ -0,0 +1,55 @@ +#include <iostream> +#include <stdlib.h> +// using namespace std; + +class STUDENT { + char name[20]; + char USN [11]; + int marks[3]; + float average; +public: + void input(void); + void output(void); + void calcAverage(void); +}; +// int min(int, int); + +int main() { + int size; + do{ + std::cout << "\nEnter number of students: "; + std::cin >> size; + if(size < 1) + std::cout << "\nInvalid size, try again.\n"; + } while (size < 1); + STUDENT *s = (STUDENT*)malloc(sizeof(STUDENT) * size); + if(!s) { + std::cout << "\nInsufficient memory.\n"; + return 0; + } + std::cout << "\nEnter the name, USN, and marks of three tests.\n"; + for(int i = 0; i < size; i++) + (*(s + i)).input(); + std::cout << "\nThe name, USN, and marks of the students are:\n"; + for(int i = 0; i < size; i++) + (*(s + i)).output(); + return 0; +} + +int min (int x, int y){ + return (x > y ? y : x); +} + +void STUDENT::calcAverage(void) { + average = marks[0] + marks [1] + marks[2] - min(marks[0], min(marks[1], marks[2])); + average/=2; +} + +void STUDENT::input(void) { + std::cin >> name >> USN >> marks[0] >> marks[1] >> marks[2]; + calcAverage(); +} + +void STUDENT::output(void) { + std::cout << std::endl << "Name: " << name << std::endl << "USN: " << USN << std::endl << "Average: " << average << std::endl << "====================" << std::endl; +}