Logo

Ctrl+V Thread

Register Log In Back To Forums

Post #1501 · Posted at 2014-01-14 01:57:02am 11.4 years ago

Offline RGTM
RGTM Avatar Moderator+
7,262 Posts
United States
Reg. 2007-07-19

Nintendo Network ID: xRGTMxNintendo Switch Friend Code: SW-6034-2315-7724Game Center Nickname: xRGTMx
"BBCode Not Allowed"
/*
Name: student.cpp
Author: xRGTMx
Date: 1/8/2014 12:00
Description: This program uses a text file named studData.txt as input, which
contains the first and last names of each student, and two test
scores. The program takes the first and last names of the student,
adds the two test scores, and gives the overall rank of the students.
Students who have an F are not ranked.
*/

// header
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>

using namespace std;

// declare function prototypes
char calculateGrade(double tot); // parameter passed is not an array

int main()
{
ifstream inFile; // declare inFile as an object of ifstream
ofstream outFile; // decleare outFile as an object of ofstream

inFile.open("studData.txt"); // open input file
outFile.open("student.out");

// declare arrays
string studentLastNames[100];
string studentFirstNames[100];
double score1[100];
double score2[100];
double fTotal[100];
char fGrade[100];

// declare variables
double total;
char grade;

// counter will keep track of all records
int counter = 0;

// error message if input file is not found
if (!inFile)
{
cout << "Cannot open the input file." << endl;
system("Pause");
return 1;
}//end if


while (!inFile.eof())
{
// read data within input file
inFile >> studentLastNames[counter] >> studentFirstNames[counter]
>> score1[counter] >> score2[counter];

// calculate total by adding two scores of each record
total = score1[counter] + score2[counter];

fTotal[counter] = total;
grade = calculateGrade(total);
fGrade[counter] = grade;

// counter records number of records
counter = counter + 1;
} //end while

// sort all records using Bubble sort algorithm

// declare sort variables
string temp, temp1;
double temp2, temp3, temp4;
char temp5;

// the following loop will sort the records by total
for (int iteration = 1; iteration < counter; iteration++)
{
for (int index = 0; index < counter - iteration; index++)
{
if (fTotal[index] < fTotal[index + 1])
{
temp = studentLastNames[index];
temp1 = studentFirstNames[index];
temp2 = score1[index];
temp3 = score2[index];
temp4 = fTotal[index];
temp5 = fGrade[index];

studentLastNames[index] = studentLastNames[index + 1];
studentFirstNames[index] = studentFirstNames[index +1];
score1[index]= score1[index+1];
score2[index] = score2[index+1];
fTotal[index] = fTotal[index+1];
fGrade[index] = fGrade[index+1];

studentLastNames[index + 1] = temp;
studentFirstNames[index + 1] = temp1;
score1[index + 1] = temp2;
score2[index +1] = temp3;
fTotal[index +1] = temp4;
fGrade[index +1] = temp5;
} // end if
} // end for
} // end for

// header for output file
outFile << "\t\t CIS350 - Software Design\t\t\n";
outFile << "\t\t-----------------------------\t\t\n";
outFile << "\t\t Spring 2012 Grade Sheet\t\t\n";
outFile << "\t\t-----------------------------\t\t\n" << endl;

// column headers and border
outFile << setw(9) << "Last Name" << setw(12) << "First Name"
<< setw(10) << "Score 1" << setw(10) << "Score 2"
<< setw(15) << "Total" << setw(15) << "Grade"
<< setw(10) << "Rank" << endl;
outFile << "----------------------------------------------------------------------------------" << endl;

// data for output file will be written in this loop

for (int i = 0;i < counter; i++)
{
outFile << fixed << showpoint << setprecision(2);
outFile << setw(12) << left << studentLastNames[i] << setw(15)
<< studentFirstNames[i] << setw(10) << left << setw(10)
<< score1[i] << setw(10) << score2[i] << setw(10)
<< right << fTotal[i] << setw(10)
<< setw(11) << right << fGrade[i];

if (fGrade[i] != 'F')
outFile << right << setw(10) << i + 1 << endl;

else
outFile << endl;
}//end for

// close all files
inFile.close();
outFile.close();

// print message to user
cout << "Please open 'student.out' to view report.\n" << endl;

system("pause");
return 0;
} // end main

// function to calculate lettter grade, returining a character value
char calculateGrade(double tot)
{
if (tot >= 90)
return 'A';
else if (tot >= 80)
return 'B';
else if (tot >= 70)
return 'C';
else if (tot >= 60)
return 'D';
else
return 'F';
} // end calculateGrade

ZIv Mod Squad: "shark jumpscare"
https://i.imgur.com/YdfMaWU.gif

Post #1502 · Posted at 2014-01-14 01:57:32am 11.4 years ago

Offline Astroman129
Astroman129 Avatar Member
1,958 Posts
United States
Reg. 2010-02-25

Nintendo Switch Friend Code: SW-6942-4517-60103DS Friend Code: 0645-5928-9360
" ♫~~ I'm wired to the world ~~♫"
new user alert

Post #1503 · Posted at 2014-01-14 02:36:39am 11.4 years ago

Offline Dogman1227
Dogman1227 Avatar Member
289 Posts
United States
Reg. 2011-02-27

Nintendo Network ID: Dogman1227
"*no witty comment available* "

*insert crap bemani joke here*

Post #1504 · Posted at 2014-01-14 03:22:03am 11.4 years ago

Offline Hiryuu
Hiryuu Avatar Member
614 Posts
United States
Reg. 2008-11-23

Nintendo Network ID: Rainhiryuu3DS Friend Code: 4699-5240-4471
"Retired?"

Post #1505 · Posted at 2014-01-14 06:00:39am 11.4 years ago

Online Pandemonium X
Pandemonium X Avatar Member
10,356 Posts
United States
Reg. 2007-04-06

Nintendo Network ID: PandemoniumEJPNintendo Switch Friend Code: SW-2916-7192-8116

Post #1506 · Posted at 2014-01-14 03:45:35pm 11.4 years ago

Offline Hiryuu
Hiryuu Avatar Member
614 Posts
United States
Reg. 2008-11-23

Nintendo Network ID: Rainhiryuu3DS Friend Code: 4699-5240-4471
"Retired?"
[19:10] <Hitagi> http://prntscr.com/2j5hsn
[19:11] <Hiryuu> oh fuck right off with your AAAs of fucking Anti-Matter

Post #1507 · Posted at 2014-01-15 06:02:37am 11.4 years ago

Offline ohaiimian
ohaiimian Avatar Member
1,026 Posts
United States
Reg. 2012-07-02

BALALAIKA, CARRIED WITH THE WIND

Post #1508 · Posted at 2014-01-15 06:24:36am 11.4 years ago

Offline Hiryuu
Hiryuu Avatar Member
614 Posts
United States
Reg. 2008-11-23

Nintendo Network ID: Rainhiryuu3DS Friend Code: 4699-5240-4471
"Retired?"

Post #1509 · Posted at 2014-01-15 07:47:00am 11.4 years ago

Post #1510 · Posted at 2014-01-15 08:21:09am 11.4 years ago

Offline Hiryuu
Hiryuu Avatar Member
614 Posts
United States
Reg. 2008-11-23

Nintendo Network ID: Rainhiryuu3DS Friend Code: 4699-5240-4471
"Retired?"

Post #1511 · Posted at 2014-01-15 11:14:52am 11.4 years ago

Offline Sigrev2
Sigrev2 Avatar Member+
4,216 Posts
United States
Reg. 2009-10-17

Nintendo Network ID: Sigrev2Nintendo Switch Friend Code: SW-2884-7660-37993DS Friend Code: 3883-7652-3160
"suffering from success"
It's a real shame when the people who are the least deserving get the most over.

Post #1512 · Posted at 2014-01-15 08:02:51pm 11.4 years ago

Offline SM MaxX
SM MaxX Avatar Member+
911 Posts
United States
Reg. 2012-08-30

Nintendo Switch Friend Code: SW-1495-0040-1058
"I play too much touhou"
Mahou Shoujo Madoka★Magica
http://i.imgur.com/EvGgqSs.png

Post #1513 · Posted at 2014-01-16 12:05:56am 11.4 years ago

Online Pandemonium X
Pandemonium X Avatar Member
10,356 Posts
United States
Reg. 2007-04-06

Nintendo Network ID: PandemoniumEJPNintendo Switch Friend Code: SW-2916-7192-8116

Post #1514 · Posted at 2014-01-16 12:06:29am 11.4 years ago

Post #1515 · Posted at 2014-01-16 12:48:00am 11.4 years ago

Offline Aegis
Aegis Avatar Member
9,369 Posts
United States
Reg. 2009-04-16

"."
U V B - 7 6

Encrypt. Disable. Never. Available.
Disillusion. Intuition. Motivate. Instinct.
Future. Vanity. Past. Glory.
Govern. Life. Poor. Spirit.



<link rel="stylesheet" type="text/css" href="/fancybox/jquery.fancybox-1.3.1.css" />

_
_


__
_____
______________________
______________
__
_______
__
__
____________
___
_
_
_

Post #1516 · Posted at 2014-01-16 01:03:12am 11.4 years ago

Online -Viper-
-Viper- Avatar Member+
2,416 Posts
United States
Reg. 2007-10-26

3DS Friend Code: 1091-8797-8693
Encrypt. Disable. N[i]e

Post #1517 · Posted at 2014-01-16 09:28:48am 11.4 years ago

Offline Hiryuu
Hiryuu Avatar Member
614 Posts
United States
Reg. 2008-11-23

Nintendo Network ID: Rainhiryuu3DS Friend Code: 4699-5240-4471
"Retired?"

Last updated: 2014-01-16 09:28am
https://www.youtube.com/watch?feature=player_embedded&v=6XSEi1jTR58

[19:23] <FPzero> I'm dinner
[19:24] <Tyty> brb dish
[19:24] <Hiryuu> k spoon

Post #1518 · Posted at 2014-01-16 09:14:57pm 11.4 years ago

Offline ohaiimian
ohaiimian Avatar Member
1,026 Posts
United States
Reg. 2012-07-02

Cosmic Hurricane -Try to Sing Ver.-

Post #1519 · Posted at 2014-01-21 08:09:52am 11.4 years ago

Post #1520 · Posted at 2014-01-21 08:29:22am 11.4 years ago

Offline Adamn
Adamn Avatar Member
187 Posts
United States
Reg. 2007-09-06

HERNÁN
Register Log In Back To Forums

0 User(s) Viewing This Thread (Past 15 Minutes)

©2006-2025 Zenius -I- vanisher.com -5th style- IIPrivacy Policy
Web Server: 17% · Database: 8% · Server Time: 2025-07-06 02:59:42
This page took 0.024 seconds to execute.
Theme: starlight · Language: englishuk
Reset Theme & Language