The beast has been pwned.

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

The beast has been pwned.

Post by Falco Girgis »

We had this group project thingy that was due over a course of like a few days. I stupidly didn't even bother starting until yesterday and it is due today. Well, I'm proud because not only am I a group of only myself, but I got every function done for extra credit.

This program is nothing hardcore or even hard, it is just time-consuming and now the sonnuva bitch can quit preventing me from working on BomberMan SDL.

Here's the inheritance project:

Code: Select all

#include <stdio.h>
#include <iostream>

class Person {
    protected:
        char name[50];
        unsigned long int ssno;
    public:     
        Person() {}
        Person(char *n, int no) {
            strcpy(name, n);
            ssno = no;
        }
        char *get_name() { return name; }
        unsigned long int get_ssno() { return ssno; }
};

class Student: public Person {
    private:
        float grade[4];
    public:
        Student() {
            strcpy(name, "No name.");
            ssno = 12345;
            grade[0] = 10;
            grade[1] = 20;
            grade[2] = 30;
            grade[3] = 40;             
        }
        void Set(char *n, unsigned long int no, float g1, float g2, float g3, float g4) {
            strcpy(name, n);
            ssno = no;
            grade[0] = g1;
            grade[1] = g2;
            grade[2] = g3;
            grade[3] = g4;             
        }
        float Average() {
            return (grade[0] + grade[1] + grade[2] + grade[3])/4;     
        }   
        float get_g1() { return grade[0]; }
        float get_g2() { return grade[1]; }
        float get_g3() { return grade[2]; }
        float get_g4() { return grade[3]; }
};

class Teacher: public Person {
    private:
         float salary;
    public:
         void Set(char *n, unsigned long int no, float s) {
            strcpy(name, n);
            ssno = no;
            salary = s;             
        }
        float Salary() {
            if(salary > 50000)
                 return salary - salary * .3;
            if(salary > 30000)
                 return salary - salary * .2;
            if(salary <= 30000)
                 return salary - salary * .15;
        }
        float get_salary() { return salary; }           
};


int Menu(Student student[], int &s_index, Teacher teacher[], int &t_index);
void AddStudent(Student student[], int &s_index, Teacher teacher[], int &t_index);
void OrderStudentsAvg(Student student[], int &s_index, Teacher teacher[], int &t_index);
void OrderStudentsAlpha(Student student[], int &s_index, Teacher teacher[], int &t_index);
void DeleteStudent(Student student[], int &s_index, Teacher teacher[], int &t_index);
void AddTeacher(Student student[], int &s_index, Teacher teacher[], int &t_index);
void DeleteTeacher(Student student[], int &s_index, Teacher teacher[], int &t_index);
void OrderTeachersAlpha(Student student[], int &s_index, Teacher teacher[], int &t_index);
void OrderTeachersSalary(Student student[], int &s_index, Teacher teacher[], int &t_index);

using namespace std;

int main() {
    Student student[5];
    int s_index = 0;
    Teacher teacher[5];
    int t_index = 0;
   
    if(!Menu(student, s_index, teacher, t_index)) return 0;
   
    system("PAUSE");
    return 0;
}

int Menu(Student student[], int &s_index, Teacher teacher[], int &t_index) {
     int choice;
     printf("1) Add Student\n2) Add Teacher\n3) Display all Students in Ascending Alphabetical Order\n");
     printf("4) Display all students from highest to lowest average. \n5) Display all teachers in ascending alphabetical order\n");
     printf("6) Display all teachers by net salary (highest to lowest)\n7) Delete a Student\n8) Delete a Teacher\n9) Exit\n");
     cin >> choice;
     switch(choice) {
         case 1:
              AddStudent(student, s_index, teacher, t_index);
              break;
         case 2:
              printf("%d\n", t_index);
              AddTeacher(student, s_index, teacher, t_index);
              break;
         case 3:
              OrderStudentsAlpha(student, s_index, teacher, t_index);
              break;
         case 4:
              OrderStudentsAvg(student, s_index, teacher, t_index);
              break;
         case 5:
              OrderTeachersAlpha(student, s_index, teacher, t_index);
              break;
         case 6:
              OrderTeachersSalary(student, s_index, teacher, t_index);
              break;
         case 7:
              DeleteStudent(student, s_index, teacher, t_index);
              break;
         case 8:
              DeleteTeacher(student, s_index, teacher, t_index);
         case 9:
              return 0;
              break;
         default:
             printf("What's wrong with you? That wasn't even a choice!\n");
             Menu(student, s_index, teacher, t_index);
     }
     return 1;
}

void AddStudent(Student student[], int &s_index, Teacher teacher[], int &t_index) {
    char name[30];
    unsigned long int social;
    float grade[4];
    printf("What is the name of this student?\n");
    cin >> name;
    printf("Enter his/her social security number.\n");
    cin >> social;
    for(int i = 0; i < 4; i++) {
        printf("What did they have for grade #%d?\n", i);
        cin >> grade[i];
    }
    student[s_index].Set(name, social, grade[0], grade[1], grade[2], grade[3]);
    s_index++;
    printf("Student successfully added!\n\n");
    Menu(student, s_index, teacher, t_index);
} 


void OrderStudentsAvg(Student student[], int &s_index, Teacher teacher[], int &t_index) {
     Student temp;
     for(int i = 0; i < s_index; i++)
         for(int j = 0; j < s_index; j++)
             if(student[i].Average() > student[j].Average()) {
                  temp.Set(student[j].get_name(), student[j].get_ssno(), student[j].get_g1(), student[j].get_g2(), student[j].get_g3(), student[j].get_g4());
                  student[j].Set(student[i].get_name(), student[i].get_ssno(), student[i].get_g1(), student[i].get_g2(), student[i].get_g3(), student[i].get_g4());
                  student[i].Set(temp.get_name(), temp.get_ssno(), temp.get_g1(), temp.get_g2(), temp.get_g3(), temp.get_g4());                   
             } 
             
     for(int k = 0; k < s_index; k++) {
         printf("Name - %s\nSocial Security No - %d\nAverage - %.0f\n\n", student[k].get_name(), student[k].get_ssno(), student[k].Average());       
     }
     Menu(student, s_index, teacher, t_index);
}

void OrderStudentsAlpha(Student student[], int &s_index, Teacher teacher[], int &t_index) {
     Student temp;
     for(int i = 0; i < s_index; i++)
         for(int j = 0; j < s_index; j++)
             if(strcmp(student[i].get_name(), student[j].get_name()) < 0) {
                  temp.Set(student[j].get_name(), student[j].get_ssno(), student[j].get_g1(), student[j].get_g2(), student[j].get_g3(), student[j].get_g4());
                  student[j].Set(student[i].get_name(), student[i].get_ssno(), student[i].get_g1(), student[i].get_g2(), student[i].get_g3(), student[i].get_g4());
                  student[i].Set(temp.get_name(), temp.get_ssno(), temp.get_g1(), temp.get_g2(), temp.get_g3(), temp.get_g4());                      
             } 
             
     for(int k = 0; k < s_index; k++) {
         printf("Name - %s\nSocial Security No - %d\n\n", student[k].get_name(), student[k].get_ssno());       
     }
     Menu(student, s_index, teacher, t_index);
}

void DeleteStudent(Student student[], int &s_index, Teacher teacher[], int &t_index) {
     for(int i = 0; i < s_index; i++)
             printf("STUDENT NUMBER - %d\nName - %s\nSocial Security No - %d\n\n", i, student[i].get_name(), student[i].get_ssno());
     printf("Enter the student number you'd like to delete.\n");
     int todelete;
     cin >> todelete;
      for(int k = todelete+1; k <= s_index; k++)
         student[k-1].Set(student[k].get_name(), student[k].get_ssno(), student[k].get_g1(), student[k].get_g2(), student[k].get_g3(), student[k].get_g4());
         
     s_index--;
     
     printf("Successfully deleted!\n\n");
     Menu(student, s_index, teacher, t_index);
}

void AddTeacher(Student student[], int &s_index, Teacher teacher[], int &t_index) {
    char name[30];
    unsigned long int social;
    float salary;
    printf("What is the name of this teacher?\n");
    cin >> name;
    printf("Enter his/her social security number.\n");
    cin >> social;
    printf("What is this teacher's salary?\n");
    cin >> salary;
    teacher[t_index].Set(name, social, salary);
    t_index++;
    printf("Teacher successfully added!\n\n");
    Menu(student, s_index, teacher, t_index);
} 

void DeleteTeacher(Student student[], int &s_index, Teacher teacher[], int &t_index) {
     for(int i = 0; i < t_index; i++)
             printf("TEACHER NUMBER - %d\nName - %s\nSocial Security No - %d\n\n", i, teacher[i].get_name(), teacher[i].get_ssno());
     printf("Enter the teacher number you'd like to delete.\n");
     int todelete;
     cin >> todelete;
     for(int k = todelete+1; k < t_index; k++)
         teacher[k-1].Set(teacher[k].get_name(), teacher[k].get_ssno(), teacher[k].get_salary());
         
     t_index--;
     
     printf("Successfully deleted!\n\n");
     Menu(student, s_index, teacher, t_index);
}

void OrderTeachersAlpha(Student student[], int &s_index, Teacher teacher[], int &t_index) {
     Teacher temp;
     for(int i = 0; i < t_index; i++)
         for(int j = i+1; j < t_index; j++)
             if(strcmp(teacher[i].get_name(), teacher[j].get_name()) > 0) {
                  temp.Set(teacher[j].get_name(), teacher[j].get_ssno(), teacher[j].get_salary());
                  teacher[j].Set(teacher[i].get_name(), teacher[i].get_ssno(), teacher[j].get_salary());
                  teacher[i].Set(temp.get_name(), temp.get_ssno(), teacher[j].get_salary());                                
             } 
             
     for(int k = 0; k < t_index; k++) {
         printf("Name - %s\nSocial Security No - %d\n\n", teacher[k].get_name(), teacher[k].get_ssno());       
     }
     Menu(student, s_index, teacher, t_index);
}

void OrderTeachersSalary(Student student[], int &s_index, Teacher teacher[], int &t_index) {
     Teacher temp;
     for(int i = 0; i < t_index; i++)
         for(int j = 0; j < t_index; j++)
             if(teacher[i].Salary() > teacher[j].Salary()) {
                  temp.Set(teacher[j].get_name(), teacher[j].get_ssno(), teacher[j].get_salary());
                  teacher[j].Set(teacher[i].get_name(), teacher[i].get_ssno(), teacher[j].get_salary());
                  teacher[i].Set(temp.get_name(), temp.get_ssno(), teacher[j].get_salary());                                      
             } 
             
     for(int k = 0; k < t_index; k++) {
         printf("Name - %s\nSocial Security No - %d\nSalary - %.0f\n\n", teacher[k].get_name(), teacher[k].get_ssno(), teacher[k].Salary());       
     }
     Menu(student, s_index, teacher, t_index);
}
Pwned.

Oh dear god, that stupid Geometry Origami project is due tomorrow and I haven't even started...
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Ewww.... busy work...

Man, I would have grouped up with five other peeps to pull that mug off. Wouldn't take that long then.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
TiredSikTwisted
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 72
Joined: Sat Feb 05, 2005 1:11 pm
Location: /root
Contact:

Post by TiredSikTwisted »

JS Lemming wrote:Ewww.... busy work...

Man, I would have grouped up with five other peeps to pull that mug off. Wouldn't take that long then.
Agreed, OS PWNS WORK TIME!
Image
精神の屈折:復讐
#animeflix @ irc.aniverse.com
Official Internet Relay Chat Moderator Guy (OircMG) of animeflix.info
Guest

Post by Guest »

Wow, that's great! OMG I wish I had time to get more in depth in my C++ learnage.

I'd like to thank everyone here for posting. Unlike other forums, here in Programming Discussion, we enjoy and savor your every post. :lol:
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

Arce, where are you going with the thank you for posting bit? Your spamm'n the grill.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Post Reply