C++

//Dengan menggunakan structur (struct) di dalam C++, bina satu program untuk memasukkan
//maklumat pelajar yang merangkumi nama, nom_matrik dan gred bagi subjek2 yang diambil
//pada semster lepas. Seterusnya program akan memaparkan semua maklumat yang dimasukkan
//termasuklah GPA bagi pelajar tersebut.

#include <iostream.h>
#include <istream.h>
#include <string>
#include <fstream>
using namespace std;

struct database{
string name;
string matrik;
string subjek[7];
string gred[7];
};
int main()
{
database pelajar;
float pointer,point;
float total_jkredit,jkredit;
float total_overal;
float gpa;
string gred;
string temp;

cout<<" NAME : ";
getline(cin,pelajar.name);
cout<<" \n NO MATRIK : ";
getline(cin,pelajar.matrik);
cout<<endl;

int i;
for(i=0;i<2;i++)
{
cout<<" Subjek : ";
getline(cin,pelajar.subjek[i]);

cout<<" Masukkan Jam Kredit : ";
getline(cin,temp);

cout<<" Gred : ";
getline(cin,pelajar.gred[i]);
cout<<endl;

gred=pelajar.gred[i];

if (gred == "A")
point=4.0;
else if (gred == "A-")
point= 3.7;
else if (gred == "B+")
point= 3.5;
else if (gred == "B")
point= 3.0;
else if (gred == "B-")
point= 2.7;
else if (gred == "C+")
point= 2.5;
else if (gred == "C")
point= 2.0;
else if (gred == "C-")
point= 1.7;
else if (gred == "D+")
point= 1.5;
else if (gred == "D")
point= 1.0;
else
point= 0;

pointer=point*jkredit;
total_jkredit+=jkredit;
total_overal+=total_jkredit;
}
gpa/=(total_overal/total_jkredit);

cout<<"\n******************************"<<endl;
cout<<" MAKLUMAT PELAJAR SEMESTER 2 "<<endl;
cout<<"*******************************"<<endl;
cout<<" Nama : " <<pelajar.name<<endl;
cout<<" Matrik : " <<pelajar.matrik<<endl;

for(i=0;i<2;i++)
{
cout<<" Subjek : " <<pelajar.subjek[i]<<"("<<pelajar.gred[i]<<")"<<endl;
}
cout<<" GPA : " <<gpa<<endl;
}
Topic archived. No new replies allowed.