473,473 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

A program that accepts the information and calculated CGPA

4 New Member
i want to display the grade report of two students in the table but this code will repeat the grade report of one student in the tables and what is wrong with this code below ?
please guy just help me !!

#include<iostream>
#include<string>
#include<fstream>
using namespace std;

class student{

private:

string fname;
string lname;
char sex;
string id;
char grade[20];
int year;
int semester;
int nocourse;
string coursename[20];
int crhr[20];
int coursecrhr[20];
int totalcrhr = 0;
int point[20];
int totalpoint = 0;
double cgpa;
public:

void acceptdata(){

cout << "Enter year: " << endl;
cin >> year;

cout << "Enter semester: " << endl;
cin >> semester;

cout << "Number of course: " << endl;
cin >> nocourse;

for (int i = 1; i <= nocourse; i++)
{

cout << "Course Name: ";
cin >> coursename[i];

cout << "Credit hour: ";
cin >> crhr[i];


}

}

void studinfo(){
for (int i = 1; i <= nocourse; i++){

cout << "Student name: ";
cin >> fname;

cout << "Student id: ";
cin >> id;

cout << "Student sex: ";
cin >> sex;
}
G:
for (int i = 1; i <= nocourse; i++){
cout << "Grade for " << coursename[i] << ":";
cin >> grade[i];
if (grade[i] == 'A'){
point[i] = 4;
}
else if (grade[i] == 'B')
{
point[i] = 3;
}
else if (grade[i] == 'C'){
point[i] = 2;
}
else if (grade[i] == 'D')
{
point[i] = 1;
}
else if (grade[i] == 'F')
{
point[i] = 0;
}
else
{
cout << "Please enter correct grade in capital letter!" << endl;
goto G;
}
}

}

void gradecalc(){
for (int i = 1; i <= nocourse; i++){
totalcrhr += crhr[i];
totalpoint += crhr[i] * point[i];
}
cgpa = totalpoint / totalcrhr;
cout << "_________________________________________________ ____________________________" << endl;
cout << " Jigjiga University " << endl;
cout << " Name: " << fname;
cout << " Sex: " << sex;
cout << " ID: " << id;
cout << " year: " << year;
cout << " Semester: " << semester << endl;
cout << "-----------------------------------------------------------------------------" << endl;
cout << "Sno \t Course Name \t CrHr \t\t Grade \t\t Point" << endl;
cout << "-----------------------------------------------------------------------------" << endl;
for (int i = 1; i <= nocourse; i++){
cout << i << " \t" << coursename[i] << " \t" << crhr[i] << " \t\t" << grade[i] << " \t\t" << point[i] << endl;
}
cout << "_________________________________________________ ____________________________" << endl;
cout << "Total Point: " << totalpoint;
cout << "\t\t\t\t CGPA: " << cgpa << endl;
}

};

int main()
{
student s,s1;

s.acceptdata();
s.studinfo();
s.gradecalc();
s1.acceptdata();
s1.studinfo();
s1.gradecalc();

return 0;

}
Jan 30 '15 #1

✓ answered by weaknessforcats

It works for me.

However, I had to remove that goto that was stopping your for loop from working.

goto is an ancient curse from C. It should never appear in a C++ program.

3 4078
weaknessforcats
9,208 Recognized Expert Moderator Expert
It works for me.

However, I had to remove that goto that was stopping your for loop from working.

goto is an ancient curse from C. It should never appear in a C++ program.
Jan 30 '15 #2
Dizzy
4 New Member
Thank you now is working me too and please can you show me how to store above information or data into file name "Grade Report" and show me with with simple example.
Jan 31 '15 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
Create an fstream object and use the << operator to put data in the file.

Expand|Select|Wrap|Line Numbers
  1. fstream myfile("GradeReport.txt");
  2.         myfile << data;
If you need to read data from the file use the >> operator. However, in this case be sure you have the data in the file in a known format.

There are a lot of examples on the Internet for this.
Jan 31 '15 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Peter Nolan | last post by:
Hi All, I have written some software that performs ETL processing to load data warehouses. Each program accepts a set of parameters and returns 0 or 1 to the win/unix shell to indicate success or...
3
by: Daniel | last post by:
Hi, Does anyone know if it is possible to interact with another console based program. For example, relaying data back and forth between the user and the program. ie. 1. User interacts with...
3
by: David | last post by:
Hi! I would like my C program to fetch data from Microsoft Outlook, stuff like calendar, contacts and so on. Does anyone know if this is even possible? Does anyone have any ideas of where to...
2
by: jacob navia | last post by:
I am developing an IDE since a few years, and after many trials I have settled for SQL databases for storing information about the program. The information I gather is o type information o...
6
by: Crooter | last post by:
Hello colleagues, Could anybody tell me if there are existing open-source solutions to extract the program tree using a program source code? I'm aware that GCC has program flow information and...
3
by: Dean Slindee | last post by:
Need to write a standalone application that processes data once per day. Looking for the application program types available that would satisfy these requirements: Requirements: 1. Unattended...
2
by: Dizzy | last post by:
#include<fstream> #include<iostream> #include<string> using namespace std; class student{ private: string fname; string lname ; char sex; ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.