Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

Student Grade Calculator

Posted by Circuit Negma on March 20, 2006


/*
 *  Copyright © 1997-2003 Metrowerks Corporation.  All Rights Reserved.
 *
 *	Created By: Circuit Negma
 *
 *	Date	  : March 20, 2006
 *
 *	File	  : ch3_studentid.cpp
 *
 *	Description: retrieve student data and then calculate the student average.
 */

// Declare Header Files
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;


int main()
{
	
	// Declare File Stream Variables
	ifstream inData;	// Read data from file "inData.txt"
	ofstream outData;	// Write data to file "outData.txt"
	
	// Declare input Variables
	int		gre1, gre2, gre3, gre4, gre5;
	char	stdID;
	double	avg;
	
	// Init files
	inData.open("inData.txt");
	outData.open("outData.txt");
	outData << fixed << showpoint << setprecision(2);

	cout << fixed << showpoint << setprecision(2);
	cout << "Student Grade Calculator" << flush << endl << endl;
	
	// Get the required data from the "inData.txt" file
	inData >> stdID;
	inData >> gre1 >> gre2 >> gre3 >> gre4 >> gre5;
	
	// Print out the data
	cout << "Student ID: " << stdID <<flush <<endl;
	outData << "Student ID: " << stdID <<endl;
	
	cout << "Course Marks: " << gre1 << " " << gre2 << " " << gre3
		 << " " << gre4 << " " << gre5 << flush << endl;
	outData	<< "Course Marks: " << gre1 << " " << gre2 << " " << gre3
		 	<< " " << gre4 << " " << gre5 << flush << endl;
	
	// Calculate Average
	avg = (gre1 + gre2 + gre3 + gre4 + gre5) / 5;
	
	cout << "Student Average: " << avg << flush << endl;
	outData <<"Student Average: " << avg << endl;
		 	 
	
	inData.close();
	outData.close();
	
	return 0;
}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: