| ITstudent (19) | |
|
urgent Write a program to calculate the grade point average (CGPA) of the student. Students are required to enter the course and the grade of the subjects taken and the next program will calculate CGPA received by students. Make sure students include data for at least two semesters for the purpose of this calculation of CGPA. For each semester, show the calculation of the overall grade obtained. Your program should use a structure concepts to students and using the concept of arrays for the subjects taken. | |
|
|
|
| Jackson Marie (451) | |
|
Hi ITStudent! Can you give us your program attempt? | |
|
|
|
| ITstudent (19) | |
|
semester1 MTS3013 structure programming MTK3013 structure disckrit MTN3013 computer organization and architecture SEMESTER2 MTS3033 OBJECKT ORIENTED PROGRAMMING MTN3023 NETWORKING MTD3033 DATABASE SYSTEM | |
|
|
|
| ITstudent (19) | |
|
if (gred=='A') cout<<"4.00"; else if (gred=='A-') cout<<"3.75"; else if (gred=='B+') cout<<"3.50"; else if (gred=='B') cout<<"3.00"; else if (gred=='B-') cout<<"2.75"; else if (gred=='C+') cout<<"2.50"; else if (gred=='C') cout<<"2.00"; else if (gred=='C-') cout<<"1.75"; else if (gred=='D+') cout<<"1.50"; else if (gred=='D') cout<<"1.00"; else (gred=='F') cout<<"0.00"; | |
|
|
|
| myya6179 (10) | |
|
this is how i can suggest : #include <iostream> #include <cstdlib> #include <cstring> using namespace std; int main() { char mark [4][12]; float pmark[4], pngk; cout<<"This Program Will Calculate Your CGPA for subject SK026, QS025," <<" SB026 and SC025."<<endl; cout<<"You should enter your grade only."<<endl<<endl; cout<<"Please enter your result :"<<endl<<endl; cout<<"MATHEMATIC : "; cin>>mark[0]; cout<<endl; cout<<"CHEMISTRY : "; cin>>mark[1]; cout<<endl; cout<<"BIOLOGY : "; cin>>mark[2]; cout<<endl; cout<<"SCIENCE COMPUTER : "; cin>>mark[3]; cout<<endl; for (int a=0; a<4; a++) { if (strcmp("A", mark[a]) == 0) pmark[a]=4.0; else if (strcmp("A-", mark[a]) == 0) pmark[a]=3.67; else if (strcmp("B+", mark[a]) == 0) pmark[a]=3.33; else if (strcmp("B", mark[a]) == 0) pmark[a]=3.00; else if (strcmp("B-", mark[a]) == 0) pmark[a]=2.67; else if (strcmp("C+", mark[a]) == 0) pmark[a]=2.33; else if (strcmp("C", mark[a]) == 0) pmark[a]=2.00; else if (strcmp("D+", mark[a]) == 0) pmark[a]=1.67; else if (strcmp("E", mark[a]) == 0) pmark[a]=1.00; else pmark[a]=0; } cout<<endl<<endl; cout<<"Result MATHEMATIC ="<<" "<<mark[0]<<" ----->"<<" "<<pmark[0]<<endl; cout<<"Result CHEMISTRY ="<<" "<<mark[1]<<" ----->"<<" "<<pmark[1]<<endl; cout<<"Result BIOLOGY ="<<" "<<mark[2]<<" ----->"<<" "<<pmark[2]<<endl; cout<<"Result SCIENCE COMPUTER ="<<" "<<mark[3]<<" ----->"<<" "<<pmark[3]<<endl; pngk=((pmark[1]*6)+(pmark[2]*6)+(pmark[0]*5)+(pmark[3]*5))/22; cout<<endl<<endl; cout<<"Your PNGK is : "<<pngk<<endl; cin.get(); system ("PAUSE"); return 0; } | |
|
|
|
| ITstudent (19) | |
|
OH MY GOD... THANK YOU.. I'LL TRY USING THIS.. | |
|
|
|
| myya6179 (10) | |
| but, you should modify it first because i used geany to create it -_- | |
|
|
|
| ITstudent (19) | |
|
thanks muhammad93 ^_^ | |
|
|
|
| ITstudent (19) | |
|
THIS ONE IS ONLY FOR ONE SEMESTER ONLY RIGHT.?? NOT FOR 2 semester pngs | |
|
|
|
| myya6179 (10) | |
| i think you must use looping.. | |
|
|
|
| ITstudent (19) | |
|
i was stuck in looping and array thats why i ask for help | |
|
Last edited on
|
|
| myya6179 (10) | |
|
erm, maybe this i can help : #include <iostream> #include <cstdlib> #include <cstring> using namespace std; int main() { char mark[2]; char A = 4, A- = 3.75, B+ = 3.50, B = 3.00, B- = 2.75, C+ = 2.50, C = 2.00, C- = 1.75, D+ = 1.50, D = 1.00, F = 1.0; float pngk; cout<<"This Program Will Calculate Your CGPA for MTS3013 structure" <<" programming MTK3013 structure disckrit MTN3013 computer organization" <<" and architecture"<<endl; cout<<"You should enter your grade only."<<endl<<endl; cout<<"MTS3013 : "; cin>>mark; cout<<endl; cout<<"MTK3013 : "; cin>>mark; cout<<endl; cout<<"MTN3013 : "; cin>>mark; cout<<endl; if (mark=="A") { cout<<"4.00"; } else if (mark=="A-") { cout<<"3.75"; } else if (mark=="B+") { cout<<"3.50"; } else if (mark=="B") { cout<<"3.00"; } else if (mark=="B-") { cout<<"2.75"; } else if (mark=="C+") { cout<<"2.50"; } else if (mark=="C") { cout<<"2.00"; } else if (mark=="C-") { cout<<"1.75"; } else if (mark=="D+") { cout<<"1.50"; } else if (mark=="D") { cout<<"1.00"; } if (mark=="F") { cout<<"0.00"; } pngk=((pmark[1]*6)+(pmark[2]*6)+(pmark[0]*5)+(pmark[3]*5))/22; cout<<endl<<endl; cout<<"Your PNGK is : "<<pngk<<endl; cin.get(); system ("PAUSE"); return 0; } | |
|
|
|
| ITstudent (19) | |
|
myya6179 thanks for trying to help me... i need array for subjeks.. | |
|
|
|
| Zereo (178) | |
|
First please use code tags when posting your code in the forums (Hint the <> under format off to the right when replying). Also I would move this to the beginners forum since this does not have to do with windows programming. So I'm not sure where your stuck at ITstudent... Could you post the code you have so far and where you need help? | |
|
Last edited on
|
|
| ITstudent (19) | |
#include <iostream.h> // for input output #include <string.h> using namespace std; // for space name float average_cgpa (int, float); struct student { char name[30]; string id; string program[30], course[30]; char gred; float cgpa; }; void display(); int main() { char name[30]; string id; string program[30], course[30]; float cgpa; char gred, subject[3]; int i; for (i=1; i<4; i++) cout << "\t\ ~~~~~~~~~~~~~~~~~~~~"; cout << "\t\ student record sistem "; cout << "\t\ ~~~~~~~~~~~~~~~~~~~~"; cout << "\n insert name : "; cin >> name; cout << " \n Id number : "; cin >> id; cout << "\n course : "; getline (cin, subject[i]. course); cout << "\n insert GRED : " << gred<< endl; if (gred=='A') cout<<"4.00"; else if (gred=='A-') cout<<"3.75"; else if (gred=='B+') cout<<"3.50"; else if (gred=='B') cout<<"3.00"; else if (gred=='B-') cout<<"2.75"; else if (gred=='C+') cout<<"2.50"; else if (gred=='C') cout<<"2.00"; else if (gred=='C-') cout<<"1.75"; else if (gred=='D+') cout<<"1.50"; else if (gred=='D') cout<<"1.00"; else (gred=='F') cout<<"0.00"; } void display() { char name[30]; string id; string program[30], course[30]; float cgpa; char gred, subject[3]; int i; cout << "\n insert NAME : "<< name << endl; cout << " \n id number : "<< id << endl; cout << "\n course : "; getline (cin, subject[i]. course) << gred << endl; } | |
|
|
|
| ITstudent (19) | |
| this what i've tried to do.. it a little bit mess... | |
|
|
|
| Zereo (178) | |
|
Well again please use code tags when you post code to the forums (Hint the <> under Format: off to the right when replying) Just scanned through it since you didn't say what you were having problems with and somethings I noticed was these. 1) #include <iostream.h> You aren't suppose to have .h at the end of this header it should be this instead #include <iostream> the same goes for the string header.2) Line 28 Your for loop for (i=1; i<4; i++) has no braces! When you have multiple statements in a loop you need to enclose them in braces {}.3) line 39 getline (cin, subject[i].course); Not sure why you have .course after subject[i] but this is not the correct way to do things. Are you trying to read in course and subject?4) Line 65 should be else if(gred=='F') not just else.5) Your function void display() has acouple things wrong with it.A) You never call the function or use it so there is no point to having it. Unless your going to use it later. B) Why are you declaring variables in your function and storing inputs in them, but not returning anything? Basically anything that you store in a variable you declared in your function will be deleted right away after the function calls since you don't return anything. Not the best description Im sorry but its 7am and have been up all night ;p. Check below for more info on functions and how they work. C) Again in the function you have this getline (cin, subject[i]. course) << gred << endl; which I don't understand what your trying to do here... In subject[i] i has no value so subject[i] would be invalid. And im still not sure what your trying to do with the .course.Then are some things I noticed with the code. And I would recommend you check out these tutorials to help with learning some material you might need more info on. 1) Functions I think you don't understand how they work exactly here is a link to the website tutorial on them http://www.cplusplus.com/doc/tutorial/functions/ 2) Control structures, you might have jsut missed the braces by accident but I feel you might need some help with control structure's here is the link http://www.cplusplus.com/doc/tutorial/control/ 3) Input and Output along with how getline() works. Just a refresher here are the linkss. Input & Output http://www.cplusplus.com/doc/tutorial/basic_io/, and for getline http://www.cplusplus.com/reference/string/getline/ Them are just some things to checkup on and if you need any help with any of them or have questions just post here and we will try and help to our best of our abilities | |
|
Last edited on
|
|
| ITstudent (19) | |
thanks..... i'm having hard time in learning C++ for 3semester.... i really don't understand C++... that is my problem | |
|
|
|
| Fredbill30 (100) | |
| ITstudent, you separate the code into a 2 .cpp files, one called main.cpp and function.cpp. separate code into functions, place it in function.cpp then use the functions in main.cpp (They must share a header file). | |
|
|
|
| ITstudent (19) | |||
| |||
|
|
|||