this is my assigment, need to handup in few hours, i already tried for 2 days, please need help

Pages: 12
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.
Hi ITStudent!
Can you give us your program attempt?
semester1
MTS3013 structure programming
MTK3013 structure disckrit
MTN3013 computer organization and architecture

SEMESTER2
MTS3033 OBJECKT ORIENTED PROGRAMMING
MTN3023 NETWORKING
MTD3033 DATABASE SYSTEM
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";
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;

}
OH MY GOD...
THANK YOU.. I'LL TRY USING THIS..

but, you should modify it first because i used geany to create it -_-
thanks muhammad93
^_^
THIS ONE IS ONLY FOR ONE SEMESTER ONLY RIGHT.??

NOT FOR 2 semester pngs
i think you must use looping..
i was stuck in looping and array

thats why i ask for help
Last edited on
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;

}

myya6179

thanks for trying to help me... i need array for subjeks..
closed account (3qX21hU5)
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


#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;

}
this what i've tried to do.. it a little bit mess...
closed account (3qX21hU5)
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


thanks..... i'm having hard time in learning C++ for 3semester....
i really don't understand C++...

that is my problem
closed account (N36fSL3A)
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).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include<iostream.h>		// for inpit and output
#include<string.h>		// for string nama...
using namespace std;		// for name space..

struct student	// declare struct
{
	string name,no_matric;
	string sub_code[10],sub_name[10],sub_grade[10];
	float credit_hour[10];
}student1;

main()
{
	int credit_hours[10];
	int sem,total_subject;		//'b', 'a',total_credit_hours and total_point 
//are removed
	float value[10],gpa[10],get_point[10];
	float cgpa;
	float total_point_sem = 0; 		//Initialise value
	int total_credit_hours_sem = 0; 	//Initialise value
	cin.ignore();
	
	cout << "\t\ ================ ";
	cout << "\n\t\ STUDENT'S REKOD " << endl;
	cout << "\t\ ================ " << endl;
	
	cout << "\n ENTER STUDENT'S NAME	: ";		//Enter student's name
	getline(cin,student1.name);
	cout << " ENTER STUDENT'S MATRIC NUMBER  : "; 		//Enter student's matric number
	getline(cin,student1.no_matric);
	cout << " ENTER TOTAL SEM TAKEN	:"; 		//Total semester taken by the student
	cin >> sem;
	
	for(int a = 0; a< sem ; a++) 	//'a' declared as int in for()[newly added]
	{ 
		int b;  //newly added line,'b' choose to add it here because, if not, error will be occured : 'b' for gpa[b] will become undefined...

		int total_credit_hours = 0;		//newly added
		float total_point = 0; 		//newly added
		cout << "\n ENTER SUBJECT TAKEN FOR SEM	 : " << a+1 << ":"; //Enter total number of subject taken for each sem
		cin >> total_subject;
		for(int b = 0; b< total_subject; b++) //loop for the courses
		{
			cin.ignore();
			cout << " ENTER SUBJECT CODE	: ";  //Enter subject code
			getline(cin,student1.sub_code[b]);
			cout << " ENTER SUBJECT NAME	: ";  //Enter subject name
			getline(cin,student1.sub_name[b]);
			cout << " ENTER SUBJECT'S CREDIT HOUR	: ";  //Enter credit hours of the subject
			cin >> student1.credit_hour[b];
			cin.ignore();
			cout << " ENTER SUBJECT GRED	: ";  //Enter grade gained by student for every subject
			getline(cin,student1.sub_grade[b]);
			
			if(student1.sub_grade[b]=="A")
				value[b]=4;
			else if(student1.sub_grade[b]=="A-")
				value[b]=3.75;
			else if(student1.sub_grade[b]=="B+")
				value[b]=3.5;
			else if(student1.sub_grade[b]=="B")
				value[b]=3;
			else if(student1.sub_grade[b]=="B-")
				value[b]=2.75;
			else if(student1.sub_grade[b]=="C+")
				value[b]=2.5;
			else if(student1.sub_grade[b]=="C")
				value[b]=2;
			else if(student1.sub_grade[b]=="C-")
				value[b]=1.75;
			else if(student1.sub_grade[b]== "D+")
				value[b]=1.5;
			else if(student1.sub_grade[b]=="D")
				value[b]=1;
			else 
				value[b]=0;
			
			get_point[b] = student1.credit_hour[b] * value[b]; //multiply of credit hours and grade get for each subject
			total_credit_hours +=student1.credit_hour[b]; //total cerdit hours for a sem
			total_point += get_point[b]; //total points(multiple of credits hours and grade)get for a sem 
		}
		
		gpa[b] = total_point / total_credit_hours; //calculate GPA for each sem
		
		total_point_sem += total_point; //Total points(multiple of grade and credit hours) get for all semester
		
		total_credit_hours_sem += total_credit_hours; //credits hour get for all semester
	}
	
	cgpa = total_point_sem / total_credit_hours_sem;  //calculate CGPA
	
	cout << "\n =================================================== ";
	cout <<"\n NAME			: " << student1.name << endl;  //display name of student
	cout <<" NO MATRIC	: "<< student1.no_matric << endl;
	for(int a = 0; a< sem ; a++) //Declaration of 'a' as int in for()
	{ 
		cout <<" SUBJECT CODE \t" << " SUBJECT NAME \t" << " SUBJECT CREDIT HOURS " <<endl;
		for(int b=0; b<total_subject; b++) //Declaration of 'b' as int in for()
		{
			cout << " " << student1.sub_code[b] << " : " << student1.sub_name[b]<< " : " << student1.credit_hour[b] << endl;
		}
			cout << " GPA" <<a+1<< " : " <<gpa[a] << endl; 
	} 
			cout << " CGPA : "<<cgpa<<endl;
	
		cout << "\n =================================================== ";

}
Pages: 12