Post #1501 · Posted at 2014-01-14 01:57:02am 11.4 years ago
![]() | |
---|---|
![]() |
Moderator+ |
7,262 Posts | |
![]() | |
Reg. 2007-07-19 | |
![]() ![]() ![]() | |
"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
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
Post #1502 · Posted at 2014-01-14 01:57:32am 11.4 years ago
![]() | |
---|---|
![]() |
Member |
1,958 Posts | |
![]() | |
Reg. 2010-02-25 | |
![]() ![]() | |
" ♫~~ I'm wired to the world ~~♫" |
new user alert
Post #1503 · Posted at 2014-01-14 02:36:39am 11.4 years ago
![]() | |
---|---|
![]() |
Member |
289 Posts | |
![]() | |
Reg. 2011-02-27 | |
![]() | |
"*no witty comment available* " |
Post #1504 · Posted at 2014-01-14 03:22:03am 11.4 years ago
![]() | |
---|---|
![]() |
Member |
614 Posts | |
![]() | |
Reg. 2008-11-23 | |
![]() ![]() | |
"Retired?" |
W208D
Post #1505 · Posted at 2014-01-14 06:00:39am 11.4 years ago
![]() | |
---|---|
![]() |
Member |
10,356 Posts | |
![]() | |
Reg. 2007-04-06 | |
![]() ![]() |
Neville
Post #1506 · Posted at 2014-01-14 03:45:35pm 11.4 years ago
![]() | |
---|---|
![]() |
Member |
614 Posts | |
![]() | |
Reg. 2008-11-23 | |
![]() ![]() | |
"Retired?" |
[19:10] <Hitagi> http://prntscr.com/2j5hsn
[19:11] <Hiryuu> oh fuck right off with your AAAs of fucking Anti-Matter
[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
![]() | |
---|---|
![]() |
Member |
1,026 Posts | |
![]() | |
Reg. 2012-07-02 | |
BALALAIKA, CARRIED WITH THE WIND
Post #1508 · Posted at 2014-01-15 06:24:36am 11.4 years ago
![]() | |
---|---|
![]() |
Member |
614 Posts | |
![]() | |
Reg. 2008-11-23 | |
![]() ![]() | |
"Retired?" |
Post #1509 · Posted at 2014-01-15 07:47:00am 11.4 years ago
![]() | |
---|---|
![]() |
Member+ |
1,435 Posts | |
![]() | |
Reg. 2013-09-13 | |
Post #1510 · Posted at 2014-01-15 08:21:09am 11.4 years ago
![]() | |
---|---|
![]() |
Member |
614 Posts | |
![]() | |
Reg. 2008-11-23 | |
![]() ![]() | |
"Retired?" |
Post #1511 · Posted at 2014-01-15 11:14:52am 11.4 years ago
![]() | |
---|---|
![]() |
Member+ |
4,216 Posts | |
![]() | |
Reg. 2009-10-17 | |
![]() ![]() ![]() | |
"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
![]() | |
---|---|
![]() |
Member+ |
911 Posts | |
![]() | |
Reg. 2012-08-30 | |
![]() | |
"I play too much touhou" |
Mahou Shoujo Madoka★Magica
Post #1513 · Posted at 2014-01-16 12:05:56am 11.4 years ago
![]() | |
---|---|
![]() |
Member |
10,356 Posts | |
![]() | |
Reg. 2007-04-06 | |
![]() ![]() |
WINNER
Post #1514 · Posted at 2014-01-16 12:06:29am 11.4 years ago
![]() | |
---|---|
![]() |
Member |
614 Posts | |
![]() | |
Reg. 2008-11-23 | |
![]() ![]() | |
"Retired?" |
Post #1515 · Posted at 2014-01-16 12:48:00am 11.4 years ago
![]() | |
---|---|
![]() |
Member |
9,369 Posts | |
![]() | |
Reg. 2009-04-16 | |
"." |
D
<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
Post #1517 · Posted at 2014-01-16 09:28:48am 11.4 years ago
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
[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
![]() | |
---|---|
![]() |
Member |
1,026 Posts | |
![]() | |
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
![]() | |
---|---|
![]() |
Member |
187 Posts | |
![]() | |
Reg. 2007-09-06 | |
HERNÁN