• Announcements

    • Peraturan Umum, Sila baca !

      1) Perbincangan illegal , seperti download , provide link muat turun, lanun sebagainya ditegah dan akan dipadam tanpa notis. Sila ambil perhatian , sebarang perbincangan mengenai download men-download, sharing link yang berkait kepada illegal material: - akan dipadam serta merta - tiada kompromi, user akan diberi warn jika melakukan kesalahan sama Contoh related : - " aku tengah sedut ni.. sejam lagi siap.. " - " kat mana ko dload laju gile.. aku lagi 14 hari nk siap" 2) Spamming, double pos, smiley semata-mata adalah satu kesalahan besar, elakkan membuat susulan pos dibawah susulan sendiri. Warning tanpa notis akan diberikan. 3) Elakkan drama fanboyism , samada berkait dengan konsol, permainan pc dan sebagainya 4) Perbincangan private server tidak dibenarkan, namun multiplayer via hamachi group dibenarkan. 5) Cheat codes dibenarkan, tetapi tidak kepada [email protected] 6) Screenshot seeloknya bersaiz 640 x 480 ke bawah, sila gunakan code spoiler sekiranya tidak resize pic anda. 7) One line posting (susulan satu baris) tanpa menjawab persoalan dan tidak memberi apa-apa manfaat dikira sebagai SPAM. SILA GUNAKAN FUNGSI REPORT JIKA TERDAPAT USER/TOPIK YANG MELANGGAR PERATURAN DI ATAS. ____________________________________________________________ _______________________________ .::. Kegagalan mematuhi terma dan syarat boleh mengakibatkan posting anda di padam dan anda mendapat warn level secara percuma .::. ____________________________________________________________ _______________________________
Sign in to follow this  
Followers 0

Mengira Gpa Menggunakan Data Structure.

6 posts in this topic

Posted · Report post

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

Posted · Report post

Jap2... semua function di atas tidak berfungsi ke?

Share this post


Link to post
Share on other sites

Posted · Report post

function semua tidak boleh dipanggil di main(). saya tidak pasti masalahnya dimana.

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

[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

Posted · Report post

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

Posted · Report post

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0