Skip to content

Instantly share code, notes, and snippets.

@ikariiin
Created August 5, 2015 11:24
Show Gist options
  • Save ikariiin/6a2bc5f206c4b6e4e21f to your computer and use it in GitHub Desktop.
Save ikariiin/6a2bc5f206c4b6e4e21f to your computer and use it in GitHub Desktop.
//============================================================================
// Name : Tut2.cpp
// Author : Gourab Nag
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
class CeightE
{
public:
int students;
int seats = 95;
int extra;
void populate(int studs)
{
students = studs;
}
int getStudents()
{
return students;
}
int getBenches()
{
return seats;
}
bool fits()
{
if(students > seats)
{
return false;
}
else
{
return true;
}
}
void fit(int studs, int seats)
{
if(studs > seats)
{
extra = studs - seats;
students = students - extra;
}
else
{
string Exception = "Invalid Operation, The students can fit in the benches";
throw Exception;
}
}
};
int main() {
CeightE ourClass;
int studs;
cout << "Enter the number of students: ";
cin >> studs;
ourClass.populate(studs);
cout << "Students: " << ourClass.getStudents() << "\n";
cout << "There is a total " << ourClass.seats << " of seats\n";
if(ourClass.fits() == true)
{
cout << "My Assumption: The students fit in the class" << "\n";
}
else if(ourClass.fits() == false)
{
cout << "My Assumption: The students does not fit in the class" << "\n";
}
try
{
ourClass.fit(ourClass.getStudents(), ourClass.getBenches());
cout << "We negated the last " << ourClass.extra << " students";
cout << "There is now " << ourClass.getStudents() << " in our class";
}
catch(string err)
{
cout << err;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment