I have been having trouble with this assignment. Attached will ben the assignment guide lines and my code. Thanks for any help that is offered. My Code: #include // Needed for cin and cout #include // Needed for String variables #include #include // Needed for Input and Output Variables #include // Using namespaces using namespace std; // Constants const string FILL = "=========="; const string RULER = "123456790"; const double AVG = .55; const double MIDTERM = .20; const double FINAL = .25; // Prototype Namespace namespace myNamespace { //enum enum scoreLetter {A, B, C, D, F}; //Function Prototypes double course_grade((homeworkAverage * .55) + (midtermExam * .20) + (finalExam * .25)); myNamespace::scoreLetter score_Letter(int score) { return score >= 90 ? myNamespace::A : score >= 80 ? myNamespace::B : score >= 70 ? myNamespace::C : score >= 60 ? myNamespace::D : myNamespace::F; }; } int main() { // Declare stream variables ifstream inputData; ofstream outputData; // input file stream object std::ifstream file("performance-input.txt"); std::string input; std::vector data; // Declare Variables double homework1, homework2, homework3, homework4, homework5, homework6, homework7, homework8, homework9, homework10; double midtermExam; double finalExam; double present; double absent; double homeworkAverage; double courseGrade; string rulerLine = RULER + RULER + RULER + RULER + RULER + RULER; string fillLine = FILL + FILL + FILL + FILL + FILL + FILL; string firstName; string lastName; // Open input file inputData.open("performance-input.txt"); if (!inputData) { cout << "Cannot open input file." << "Program terminates!" << endl; return 1; } // Open output file outputData.open("performance - input.out"); outputData << fixed << showpoint << setprecision(2); inputData >> midtermExam; inputData >> finalExam; inputData >> present; inputData >> absent; homeworkAverage = (homework1 + homework2 + homework3 + homework4 + homework5 + homework6 + homework7 + homework8 + homework9 + homework10) / 10; courseGrade = (homeworkAverage * .55) + (midtermExam * .20) + (finalExam * .25); while (file >> input) // return file performance-input.txt { cout << left; cout << rulerLine << endl << endl; cout << fillLine << endl; cout << setw(10) << "| Student" << " | " << setw(21) << lastName + ", " + firstName << setw(13) << " | Grade Level" << "| " << setw(10) << "|"; cout << endl; cout << fillLine << endl; cout << setw(10) << "| Present" << " | " << present << setw(18) << " | Absent" << setw(10) << "|" << absent << setw(17) << "|" << endl; cout << fillLine << endl; cout << setw(25) << "| Homework Grades" << " | Average" << setw(19) << " | " << homeworkAverage << setw(12) << "|" << endl; cout << fillLine << endl; cout << setw(25) << "| Homework 1" << " | " << homework1 << setw(19) << "|" << setw(12) << "|" << endl; cout << setw(25) << "| Homework 2" << " | " << homework2 << setw(19) << "|" << setw(12) << "|" << endl; cout << setw(25) << "| Homework 3" << " | " << homework3 << setw(19) << "|" << setw(12) << "|" << endl; cout << setw(25) << "| Homework 4" << " | " << homework4 << setw(19) << "|" << setw(12) << "|" << endl; cout << setw(25) << "| Homework 5" << " | " << homework5 << setw(19) << "|" << setw(12) << "|" << endl; cout << setw(25) << "| Homework 6" << " | " << homework6 << setw(19) << "|" << setw(12) << "|" << endl; cout << setw(25) << "| Homework 7" << " | " << homework7 << setw(19) << "|" << setw(12) << "|" << endl; cout << setw(25) << "| Homework 8" << " | " << homework8 << setw(19) << "|" << setw(12) << "|" << endl; cout << setw(25) << "| Homework 9" << " | " << homework9 << setw(19) << "|" << setw(12) << "|" << endl; cout << setw(25) << "| Homework 10" << " | " << homework10 << setw(19) << "|" << setw(12) << "|" << endl; cout << fillLine << endl; cout << setw(25) << "| Midterm Grade:" << " | " << setw(19) << "|" << midtermExam << "|" << endl; cout << setw(25) << "| Final Exam Grade:" << " | " << setw(19) << "|" << finalExam << "|" << endl; cout << setw(25) << "| Course Grade:" << " | " << setw(19) << "|" << courseGrade << "|" << endl; cout << fillLine << endl; inputData.close(); } int homework[20]; int i; cout << "Read input data into array"; for (i = 0; i < 20; i++) { cin >> homework[i]; } return 0; }
I have been having trouble with this assignment. Attached will ben the assignment guide lines and my code. Thanks for any help that is offered.
My Code:
#include <iostream> // Needed for cin and cout
#include <string> // Needed for String variables
#include <iomanip>
#include <fstream> // Needed for Input and Output Variables
#include <
// Using namespaces
using namespace std;
// Constants
const string FILL = "==========";
const string RULER = "123456790";
const double AVG = .55;
const double MIDTERM = .20;
const double FINAL = .25;
// Prototype Namespace
namespace myNamespace {
//enum
enum scoreLetter {A, B, C, D, F};
//Function Prototypes
double course_grade((homeworkAverage * .55) + (midtermExam * .20) + (finalExam * .25));
myNamespace::scoreLetter score_Letter(int score)
{
return score >= 90 ? myNamespace::A :
score >= 80 ? myNamespace::B :
score >= 70 ? myNamespace::C :
score >= 60 ? myNamespace::D :
myNamespace::F;
};
}
int main()
{
// Declare stream variables
ifstream inputData;
ofstream outputData;
// input file stream object
std::ifstream file("performance-input.txt");
std::string input;
std::vector<std::string> data;
// Declare Variables
double homework1, homework2, homework3, homework4, homework5, homework6, homework7, homework8, homework9, homework10;
double midtermExam;
double finalExam;
double present;
double absent;
double homeworkAverage;
double courseGrade;
string rulerLine = RULER + RULER + RULER + RULER + RULER + RULER;
string fillLine = FILL + FILL + FILL + FILL + FILL + FILL;
string firstName;
string lastName;
// Open input file
inputData.open("performance-input.txt");
if (!inputData)
{
cout << "Cannot open input file."
<< "Program terminates!" << endl;
return 1;
}
// Open output file
outputData.open("performance - input.out");
outputData << fixed << showpoint << setprecision(2);
inputData >> midtermExam;
inputData >> finalExam;
inputData >> present;
inputData >> absent;
homeworkAverage = (homework1 + homework2 + homework3 + homework4 + homework5 + homework6 + homework7 + homework8 + homework9 + homework10) / 10;
courseGrade = (homeworkAverage * .55) + (midtermExam * .20) + (finalExam * .25);
while (file >> input) // return file performance-input.txt
{
cout << left;
cout << rulerLine << endl << endl;
cout << fillLine << endl;
cout << setw(10) << "| Student" << " | " << setw(21) << lastName + ", "
+ firstName << setw(13) << " | Grade Level" << "| " << setw(10) << "|";
cout << endl;
cout << fillLine << endl;
cout << setw(10) << "| Present" << " | " << present << setw(18) << " | Absent" << setw(10) << "|" << absent << setw(17) << "|" << endl;
cout << fillLine << endl;
cout << setw(25) << "| Homework Grades" << " | Average" << setw(19) << " | " << homeworkAverage << setw(12) << "|" << endl;
cout << fillLine << endl;
cout << setw(25) << "| Homework 1" << " | " << homework1 << setw(19) << "|" << setw(12) << "|" << endl;
cout << setw(25) << "| Homework 2" << " | " << homework2 << setw(19) << "|" << setw(12) << "|" << endl;
cout << setw(25) << "| Homework 3" << " | " << homework3 << setw(19) << "|" << setw(12) << "|" << endl;
cout << setw(25) << "| Homework 4" << " | " << homework4 << setw(19) << "|" << setw(12) << "|" << endl;
cout << setw(25) << "| Homework 5" << " | " << homework5 << setw(19) << "|" << setw(12) << "|" << endl;
cout << setw(25) << "| Homework 6" << " | " << homework6 << setw(19) << "|" << setw(12) << "|" << endl;
cout << setw(25) << "| Homework 7" << " | " << homework7 << setw(19) << "|" << setw(12) << "|" << endl;
cout << setw(25) << "| Homework 8" << " | " << homework8 << setw(19) << "|" << setw(12) << "|" << endl;
cout << setw(25) << "| Homework 9" << " | " << homework9 << setw(19) << "|" << setw(12) << "|" << endl;
cout << setw(25) << "| Homework 10" << " | " << homework10 << setw(19) << "|" << setw(12) << "|" << endl;
cout << fillLine << endl;
cout << setw(25) << "| Midterm Grade:" << " | " << setw(19) << "|" << midtermExam << "|" << endl;
cout << setw(25) << "| Final Exam Grade:" << " | " << setw(19) << "|" << finalExam << "|" << endl;
cout << setw(25) << "| Course Grade:" << " | " << setw(19) << "|" << courseGrade << "|" << endl;
cout << fillLine << endl;
inputData.close();
}
int homework[20];
int i;
cout << "Read input data into array";
for (i = 0; i < 20; i++)
{
cin >> homework[i];
}
return 0;
}
Step by step
Solved in 2 steps