Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class NotValidStudentException{
- private:
- char msg[256];
- public:
- NotValidStudentException(const char * msg){
- strcpy(this->msg, msg);
- }
- const void message(){
- cout << this->msg;
- }
- };
- class Student{
- private:
- char ime[50];
- int index;
- int * poeni;
- int broj;
- double zavrsenPoeni;
- static double udelIspit;
- static double udelTest;
- const void copy_obj(const Student ©){
- strcpy(this->ime, copy.ime);
- this->index = copy.index;
- this->poeni = new int[copy.broj + 1];
- for(int i=0; i<copy.broj; i++)
- this->poeni[i] = copy.poeni[i];
- this->broj = copy.broj;
- this->zavrsenPoeni = copy.zavrsenPoeni;
- }
- public:
- Student(){
- strcpy(this->ime, "Unknown");
- this->index = 0;
- this->poeni = new int[0];
- this->broj = 0;
- this->zavrsenPoeni = 0.0;
- }
- Student(const char * ime, const int index, const int * poeni, const int broj, const double zavrsenPoeni){
- strcpy(this->ime, ime);
- this->index = index;
- this->poeni = new int[broj + 1];
- for(int i=0; i<broj; i++)
- this->poeni[i] = poeni[i];
- this->broj = broj;
- this->zavrsenPoeni = zavrsenPoeni;
- }
- Student(const Student ©){
- this->copy_obj(copy);
- }
- Student &operator=(const Student ©){
- if(this != ©){
- delete [] this->poeni;
- this->copy_obj(copy);
- }
- return *this;
- }
- ~Student(){
- delete [] this->poeni;
- }
- static void examContribution(double newPercent){
- udelIspit = newPercent;
- udelTest = 1.0 - newPercent;
- }
- const double getPoeni(){
- double total=0.0;
- for(int i=0; i<this->broj; i++)
- total += this->poeni[i];
- return total;
- }
- const double sumarniPoeni(){
- double testPoints = this->getPoeni();
- if(this->getPoeni() > 100.0)
- testPoints = 100.0;
- return (this->zavrsenPoeni * udelIspit) + (testPoints * udelTest);
- }
- const int ocenka(){
- if(this->sumarniPoeni() > 0 && this->sumarniPoeni()<=49.99)
- return 5;
- else if(this->sumarniPoeni() >= 50 && this->sumarniPoeni()<=59.99)
- return 6;
- else if(this->sumarniPoeni() >= 60 && this->sumarniPoeni()<=69.99)
- return 7;
- else if(this->sumarniPoeni() >= 70 && this->sumarniPoeni()<=79.99)
- return 8;
- else if(this->sumarniPoeni() >= 80 && this->sumarniPoeni()<=89.99)
- return 9;
- else if(this->sumarniPoeni() >= 90 && this->sumarniPoeni()<=100.0)
- return 10;
- }
- friend ostream &operator << (ostream &os, Student &orig){
- os << orig.index << " " <<orig.ime << "\n";
- if(orig.getPoeni() > 100)
- os << "Testovi: " << 100 << "\n";
- else os << "Testovi: " << orig.getPoeni() << "\n";
- os << "Zavrshen ispit: " << orig.zavrsenPoeni << "\n";
- os << "Sumarni poeni: " << orig.sumarniPoeni() << "\n";
- os << "Ocenka: " << orig.ocenka() << "\n";
- return os;
- }
- const int getBroj(){
- return this->broj;
- }
- };
- class Course{
- private:
- Student *stu;
- int broj;
- public:
- Course(){
- this->stu = new Student[0];
- this->broj = 0;
- }
- ~Course(){
- delete [] this->stu;
- }
- Course &operator+=(Student &add){
- if(add.getBroj() == 0)
- throw NotValidStudentException("Korisnikot nema pravo na potpis\n");
- Student * tmp = new Student[this->broj + 1];
- for(int i=0; i<this->broj; i++)
- tmp[i] = this->stu[i];
- tmp[this->broj++] = add;
- delete [] this->stu;
- this->stu = tmp;
- return *this;
- }
- int averageMark(){
- int sum = 0;
- for(int i=0; i<this->broj; i++){
- sum += this->stu[i].ocenka();
- }
- return (sum/this->broj) + 1;
- }
- friend ostream &operator << (ostream &os, Course &orig){
- for(int i=0; i<orig.broj; i++)
- os << orig.stu[i];
- os << "Prosecna ocenka na polozenite: " <<orig.averageMark() << "\n";
- return os;
- }
- };
- double Student::udelIspit = 0.75;
- double Student::udelTest = 0.25;
- int main () {
- int testCase;
- int index;
- char name [50];
- int n;
- int * tests;
- double exam;
- double newPercent;
- cin>>testCase;
- if (testCase==1) {
- cout<<"Testing Student constructor and operator <<"<<endl;
- cin>>name;
- cin>>index;
- cin>>n;
- tests = new int [n];
- for (int i=0;i<n;i++){
- cin>>tests[i];
- }
- cin>>exam;
- Student s (name, index, tests, n, exam);
- cout<<s<<endl;
- }
- else if (testCase == 2) {
- cout<<"Testing Student copy constructor and operator <<"<<endl;
- cin>>name;
- cin>>index;
- cin>>n;
- tests = new int [n];
- for (int i=0;i<n;i++){
- cin>>tests[i];
- }
- cin>>exam;
- Student s (name, index, tests, n, exam);
- Student s1 (s);
- cout<<s1<<endl;
- } else if (testCase == 3) {
- cout<<"Testing Student operator = and operator <<"<<endl;
- cin>>name;
- cin>>index;
- cin>>n;
- tests = new int [n];
- for (int i=0;i<n;i++){
- cin>>tests[i];
- }
- cin>>exam;
- Student s (name, index, tests, n, exam);
- Student s1;
- s1=s;
- cout<<s1<<endl;
- } else if (testCase == 4) {
- cout<<"Testing Course class, operator += and operator <<"<<endl;
- Course c;
- int studentsCount;
- cin>>studentsCount;
- for (int j=0;j<studentsCount;j++) {
- cin>>name;
- cin>>index;
- cin>>n;
- tests = new int [n];
- for (int i=0;i<n;i++){
- cin>>tests[i];
- }
- cin>>exam;
- Student s (name, index, tests, n, exam);
- c+=s;
- }
- cout<<c;
- } else if (testCase == 5) {
- cout<<"Testing Course class, operator += with exceptions and operator <<"<<endl;
- Course c;
- int studentsCount;
- cin>>studentsCount;
- for (int j=0;j<studentsCount;j++) {
- cin>>name;
- cin>>index;
- cin>>n;
- tests = new int [n];
- for (int i=0;i<n;i++){
- cin>>tests[i];
- }
- cin>>exam;
- Student s (name, index, tests, n, exam);
- try {
- c+=s;
- }
- catch (NotValidStudentException e) {
- e.message();
- }
- }
- cout<<c;
- } else if (testCase == 6) {
- cout<<"Testing examContribution function in Student"<<endl;
- cin>>name;
- cin>>index;
- cin>>n;
- tests = new int [n];
- for (int i=0;i<n;i++){
- cin>>tests[i];
- }
- cin>>exam;
- Student s (name, index, tests, n, exam);
- cout<<s<<endl;
- Student::examContribution(0.6);
- cout<<s<<endl;
- } else if (testCase == 7) {
- cout<<"Test all (without exceptions)"<<endl;
- Course c;
- int studentsCount;
- cin>>studentsCount;
- for (int j=0;j<studentsCount;j++) {
- cin>>name;
- cin>>index;
- cin>>n;
- tests = new int [n];
- for (int i=0;i<n;i++){
- cin>>tests[i];
- }
- cin>>exam;
- Student s (name, index, tests, n, exam);
- c+=s;
- }
- cout<<c;
- cout<<"After change of exam percent"<<endl;
- Student::examContribution(0.55);
- cout<<c;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement