# Computing GPA and Output with Formatting

Page 1 of 1

## 0 Replies - 1737 Views - Last Post: 26 October 2008 - 09:50 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=69113&amp;s=28fcd6c397ae1fe54e2bf7cb771bc121&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 duskmon10

Reputation: 0
• Posts: 100
• Joined: 01-October 08

# Computing GPA and Output with Formatting

Posted 26 October 2008 - 09:50 AM

I need some help with the input on this problem.

-Write a program to read from an input file(StudentFile2.txt) for 15 students, which contains each individual student ID, the course code, grade points (4 for A, 3 for B, 2 for C, 1 for D, and 0 for anything else) and credit hours for five courses. It should then compute the total credit hours, the grade point average for the first 5 students and output them to a file with the following format:

Student ID: 11111
EN100 3 C
CS155 4 A
UI100 3 B
PH120 5 A
AR101 3 D
-------------------------------------------------------
Total Credit hours: 18
GPA is: 3.0

---(Note: There should be tabs where each space is after teh first line.)

So I also need help with how to calculate GPA and I also need to know how to create a new file to output the information to. But most of all my problem is the input.

Here's the code I've got so far:

```#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
void input(int & studentid, int & hours, int & coursecode, int & grade);
void output(int studentid, int hours, int coursecode, int grade;)
int main()
{
int studentid, hours;
char coursecode;
ifstream instream;
ofstream outstream;
instream.open("S:\\CS155-01\\Lab8\\StudentFile2.txt");
outstream.open("
if (instream.fail())
{
cout<<"Input file opening failed.\n";
exit(1);
}
if (outstream.fail())
{
cout<<"Output file opening failed.\n";
exit(1);
}
return 0;
}
void input(int & studentid, int & hours, int & coursecode, int & grade)
{
instream>>studentid>>endl;
instream>>

```

Thanks for any help.

This post has been edited by duskmon10: 26 October 2008 - 09:51 AM

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }