Jump to content
daisygirl

Mengira Gpa Menggunakan Data Structure.

Recommended Posts

coding tentang pengiraan gred untuk dapatkan gpa untuk seorang user. User hanya perlu masukkan nama, no.matrik, dan gred bagi setiap subjek yang dinyatakan. selepas itu, gred yang dimasukkan akan memberi nilai untuk dikira dalam function calculate_gpa, akhirnya semua data yang dimasukkan akan dipaparkan semula oleh function print. Tetapi coding dibawah hanya menjalankan proses mengisi data, proses pengiraan dan paparan semula tidak berlaku. saya nak minta pendapat member-member sekalian untuk lihat kesilapan yang perlu diperbetulkan. :D


[CODE]
#include<iostream>
#include<sstream>
using namespace std;
struct gpa
{
string nme,matric,subcode,subnme,grade;
int credit;
double gpa;
}student;
double pointcal(string gred);
double calculate_gpa(double);
void print(gpa student);

int main()
{
string grade,mystr;
int credit;


cout << "\nENTER NAME: ";
getline(cin,student.nme);
cout << "ENTER MATRIC NUMBER: ";
getline(cin,student.matric);

cout<<"\nENTER GRADE FOR THE FOLLOWING SUBJECT:-"<<endl;

cout<<"MTD3062 : Aplikasi Perkhidmatan Internet:";
getline(cin,student.grade);
cout<<"SUBJECT CREDIT :";
getline(cin,mystr);
stringstream(mystr)>>student.credit;

cout<<"FMW3032 : Wacana Akademik Bahasa Melayu:" ;
getline(cin,student.grade);
cout<<"SUBJECT CREDIT :";
getline(cin,mystr);
stringstream(mystr)>>student.credit;

cout<<"HNS2013 : Kenegaraan :";
getline(cin,student.grade);
cout<<"SUBJECT CREDIT :";
getline(cin,mystr);
stringstream(mystr)>>student.credit;

cout<<"MTS3013 : Pengaturcaraan Berstruktur: ";
getline(cin,student.grade);
cout<<"SUBJECT CREDIT :";
getline(cin,mystr);
stringstream(mystr)>>student.credit;

cout<<"CMP2011 : Pengurusan Kokurikulum: ";
getline(cin,student.grade);
cout<<"SUBJECT CREDIT :";
getline(cin,mystr);
stringstream(mystr)>>student.credit;

cout<<"MTK3013: Struktur Diskrit :";
getline(cin,student.grade);
cout<<"SUBJECT CREDIT :";
getline(cin,mystr);
stringstream(mystr)>>student.credit;

cout<<"MTN3013 : Senibina dan Organisasi Komputer:";
getline(cin,student.grade);
cout<<"SUBJECT CREDIT :";
getline(cin,mystr);
stringstream(mystr)>>student.credit;


double pointcal();
double calculate_gpa();
void print();


}
double pointcal(string grade)
{


if (grade=="A")
return 4.0;

else if(grade=="A-")
return 3.75;

else if(grade=="B+")
return 3.5;

else if(grade=="B")
return 3.25;

else if(grade=="B-")
return 3.0;

else if(grade=="C+")
return 2.75;

else if(grade=="C")
return 2.5;
else if(grade=="C-")
return 2.25;

else if(grade=="D")
return 2.0;

else if(grade=="E")
return 1.5;

else if(grade=="F")
return 1.25;

else
return 0;


}
double calculate_gpa(double gpa_s)
{
double subg,pointer,totals,totalc;
string grade;
int credit;

subg=pointcal(grade)*credit;
totals=totals+subg;
totalc=totalc+credit;
gpa_s=totals/totalc;

cout<<"GPA :"<<gpa_s;

return gpa_s;

}
void print(gpa student)
{
cout << "\nNAME: "<<student.nme;
cout << "MATRIC NUMBER: "<<cin,student.matric;

cout<<"\nMTD3062 : Aplikasi Perkhidmatan Internet:"<<student.grade;
cout<<"\nFMW3032 : Wacana Akademik Bahasa Melayu:"<<student.grade ;
cout<<"\nHNS2013 : Kenegaraan :"<<student.grade;
cout<<"\nMTS3013 : Pengaturcaraan Berstruktur: "<<student.grade;
cout<<"\nCMP2011 : Pengurusan Kokurikulum: "<<student.grade;
cout<<"\nMTK3013: Struktur Diskrit :"<<student.grade;
cout<<"\nMTN3013 : Senibina dan Organisasi Komputer:"<<student.grade;


}
[/CODE]

Share this post


Link to post
Share on other sites
[code]

double pointcal();
double calculate_gpa();
void print();
[/code]

Macam tak kena je ni..ni nak declare function ke ape ni?
Kalau nak call function, tak perlu letak return type..
Pastu, kalau nak call function yang ada parameter (input), kena la letak input pada function tu..sebab function prototype dah declare ada input untuk function tersebut, jadi tak boleh call function tanpa input.

Pastu, algo macam tak betul..ada 6 subjek kan, jadi setiap input disimpan dalam structure yang berasingan atau structure yang sama?Nampak macam dalam structure yang sama..jadi operasi mengira point grade dan cgpa hanya dilakukan pada akhir input.. ini bermakna hanya input terakhir dikira (sebab data terakhir di overwrite pada data sebelum).

sepatutnya, setiap kali data input di masukkan, operasi kira grade point dan cgpa dilakukan. Hasil grade point darab dengan kredit hour dan jumlah credit hour disimpan dalam variables sementara. Di akhir sekali, baru dikira semuanya dan dipaparkan pada output. Edited by NeoLogy

Share this post


Link to post
Share on other sites

coding ni ada bug, kalo nak key in grade make sure guna HURUF BESAR.

[code]/*
 code by [email protected]
*/ #include <iostream>
#include <sstream>
using namespace std; struct gpa
{
 string name, matric, grade[7];
 int credit[7], point[7];
}student; double pointcal(string grade);
void calculate_gpa();
void print(); void main()
{ cout << "\nENTER NAME: ";
cin>> student.name; cout << "ENTER MATRIC NUMBER: ";
cin>> student.matric; cout<<"\nENTER GRADE FOR THE FOLLOWING SUBJECT:-"<<endl; cout<<"MTD3062 : Aplikasi Perkhidmatan Internet:";
cin>> student.grade[0];
cout<<"SUBJECT CREDIT :";
cin >> student.credit[0];    cout<<"FMW3032 : Wacana Akademik Bahasa Melayu:" ;
cin>> student.grade[1];
cout<<"SUBJECT CREDIT :";
cin >> student.credit[1]; cout<<"HNS2013 : Kenegaraan :";
cin>> student.grade[2];
cout<<"SUBJECT CREDIT :";
cin >> student.credit[2]; cout<<"MTS3013 : Pengaturcaraan Berstruktur: ";
cin>> student.grade[3];
cout<<"SUBJECT CREDIT :";
cin >> student.credit[3]; cout<<"CMP2011 : Pengurusan Kokurikulum: ";
cin>> student.grade[4];
cout<<"SUBJECT CREDIT :";
cin >> student.credit[4]; cout<<"MTK3013: Struktur Diskrit :";
cin>> student.grade[5];
cout<<"SUBJECT CREDIT :";
cin >> student.credit[5]; cout<<"MTN3013 : Senibina dan Organisasi Komputer:";
cin>> student.grade[6];
cout<<"SUBJECT CREDIT :";
cin >> student.credit[6]; print(); } double pointcal(string grade)
{     
 if (grade=="A") { return 4.0;  }
 else if (grade=="A-") { return 3.75; }
 else if (grade=="B+") { return 3.5; }
 else if (grade=="B") { return 3.25; }
 else if (grade=="B-") { return 3.0; }
 else if (grade=="C+") { return 2.75; } 
 else if (grade=="C") { return 2.5; }
 else if (grade=="C-") { return 2.25; }
 else if (grade=="D") { return 2.0; }
 else if (grade=="E") { return 1.5; }
 else if (grade=="F") { return 1.25; }  
 else { return 0; }
} void calculate_gpa()
{ double gpa_s;
double total_point = 0;
double total_credit = 0;
int i; for (i=0; i<7; i++) {
 student.point[i] = pointcal(student.grade[i]) * student.credit[i];
 total_point += student.point[i];
 total_credit += student.credit[i];
}
 
gpa_s = total_point / total_credit;
cout<<"GPA: "<<gpa_s<<endl; }
void print()
{
cout<<endl;
cout<<"\nNAME: "<<student.name;
cout<<"\tMATRIC NUMBER: "<<student.matric;
cout<<"\nMTD3062 : Aplikasi Perkhidmatan Internet: "<<student.grade[0];
cout<<"\nFMW3032 : Wacana Akademik Bahasa Melayu: "<<student.grade[1];
cout<<"\nHNS2013 : Kenegaraan: "<<student.grade[2];
cout<<"\nMTS3013 : Pengaturcaraan Berstruktur: "<<student.grade[3];
cout<<"\nCMP2011 : Pengurusan Kokurikulum: "<<student.grade[4];
cout<<"\nMTK3013 : Struktur Diskrit: "<<student.grade[5];
cout<<"\nMTN3013 : Senibina dan Organisasi Komputer: "<<student.grade[6]<<endl;
calculate_gpa();
}[/code]

 

Share this post


Link to post
Share on other sites

Modifed skit function grade.. Support huruf comey dan huruf besar :D

 

double pointcal(string grade)
{     
 if (grade=="A" || grade=="a") { return 4.0;  }
 else if (grade=="A-" || grade=="a-") { return 3.75; }
 else if (grade=="B+" || grade=="b+") { return 3.5; }
 else if (grade=="B" || grade=="b") { return 3.25; }
 else if (grade=="B-" || grade=="b-") { return 3.0; }
 else if (grade=="C+" || grade=="c+") { return 2.75; } 
 else if (grade=="C" || grade=="c") { return 2.5; }
 else if (grade=="C-" || grade=="c-") { return 2.25; }
 else if (grade=="D" || grade=="d") { return 2.0; }
 else if (grade=="E" || grade=="e") { return 1.5; }
 else if (grade=="F" || grade=="f") { return 1.25; }  
 else { return 0; }
}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...