+92 332 4229 857 99ProjectIdeas@Gmail.com

GPA Calculator (Vb.net)


// GPA.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "iostream"
#include "conio.h"

using namespace std;

static int subCount=0; // subCountS TOTAL NUMER OF SUBJECTS

class GPA
{
private:
            char subjectName[35];
            float creditHours;
            float gpa;
            float finalGPA;
public:
            GPA();
            void setGPA(char*,float,float);
            void displayGPA();
            void calculateGPA();
            char*getSubjectName();
            float getCreditHours();
            float getGpa();
            float getFinalGPA();
            void setSubjectName(char *);
            void setCreditHours(float);
            void setGpa(float);
};
GPA objArr[10];
GPA::GPA()
{
            creditHours=0.0;
            gpa=0.0;
            finalGPA=0.0;
}
void GPA::setSubjectName(char*subName)
{
            strcpy(subjectName,subName);
}
void GPA::setCreditHours(float crdtHours)
{
            creditHours=crdtHours;
}
void GPA::setGpa(float gp)
{
            gpa=gp;
}
void GPA::setGPA(char *subName,float crdtHours,float gp)
{
            setSubjectName(subName);
            setCreditHours(crdtHours);
            setGpa(gp);
}
void GPA::displayGPA()
{
            cout<<"SUBJECT NAME > "<<subjectName<<endl;
            cout<<"CREDIT HOURS > "<<creditHours<<" GPA > "<<gpa<<endl;
}
void GPA::calculateGPA()
{
            float creditHours=0.0;
            float gpa=0.0;
            float tempGrades=0.0;
            float totCreditHours=0.0;
           
            for(int i=0;i<subCount;i++)
            {
                        creditHours=objArr[i].getCreditHours();
                        gpa=objArr[i].getGpa();
                        tempGrades+=creditHours*gpa;
                        totCreditHours+=creditHours;
            }
            finalGPA=tempGrades/totCreditHours;
}
float GPA::getFinalGPA()
{
            return finalGPA;
}
char* GPA::getSubjectName()
{
            return subjectName;
}
float GPA::getCreditHours()
{
            return creditHours;
}
float GPA::getGpa()
{
            return gpa;
}

class UI
{
private:
public:
            void showMenu();
            void setInput();
            void getInput();
            void putInput();
            void calculate();
};
void UI::setInput()
{
            objArr[subCount++].setGPA("ENTREPRENUERSHIP",3.0,3.3);
            objArr[subCount++].setGPA("PROGRAMMING LANGUAGES",3.0,3.3);
            objArr[subCount++].setGPA("COMPUTER GRAPHICS",3.0,3.7);
            objArr[subCount++].setGPA("COMPUTER ARCHITECTURE",3.0,3.7);
}
void UI::getInput()
{
            char opt;
            do
            {
                        char subName[35];
                        float crdtHours=0.0;
                        float gpa=0.0;

                        cout<<"ENTER NAME FOR SUBJECT NUMBER "<<subCount+1<<" > ";
                        cin.ignore(cin.rdbuf()->in_avail(),'\n');
                        cin.getline(subName,35);
                        cout<<"ENTER CREDIT HOURS FOR SUBJECT NUMBER "<<" > ";
                        cin>>crdtHours;
                        cout<<"ENTER GPA FOR SUBJECT NUMBER "<<subCount+1<<" > ";
                        cin>>gpa;

                        objArr[subCount++].setGPA(subName,crdtHours,gpa);
           
                        cout<<"WANNA ADD MORE (Y/N) ? ";
                        cin>>opt;
            }while(opt=='Y'|opt=='y');
}
void UI::putInput()
{
            for(int i=0;i<subCount;i++)
                        objArr[i].displayGPA();
}
void UI::calculate()
{
            GPA G;
            G.calculateGPA();
            cout<<"CALCULATED FINAL GPA IS > "<<G.getFinalGPA();
}
void UI::showMenu()
{
            int option=0;
            cout<<"!!!!!!!!!!!!~~~~~~~~~~~~MENU~~~~~~~~~~~~!!!!!!!!!!!!"<<endl;
            cout<<"PRESS 1 TO USE PRE-DEFINED INPUT FOR GPA CALCULATION"<<endl;
            cout<<"PRESS 2 TO TAKE INPUT FOR GPA CALCULATION"<<endl;
            cout<<"PRESS 3 TO EXIT"<<endl;
            cin>>option;

            switch(option)
            {
                        case 1:{setInput();putInput();calculate();break;}
                        case 2:{getInput();putInput();calculate();break;}
                        case 3:{exit(0);}
            }
}

int main()
{
            UI U;
            U.showMenu();

            _getche();
            return 0;
}

0 comments: