473,322 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

A program that accepts the information and calculated CGPA

4
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 4061
weaknessforcats
9,208 Expert Mod 8TB
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
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 Expert Mod 8TB
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.