Thread: can u solve for me this Question please in 2h??? or sooon??

1. can u solve for me this Question please in 2h??? or sooon??

Write a program that reads a list of students marks in a course from an input file then calculates the students grades and the class average mark and grade. Your program should input the name of the file from the user (via the keyboard).
Each line in the input file contains a student ID followed by marks in homework assignments (out of 10), in lab tests (out of 50) and in the final test (out of 40). Each of these four pieces of information is separated by a tab.
Your program should write the output to an output file called results.dat as follows:
1. For each student write the following on a line: ID followed by the total mark followed by the grade separated by tabs. Assume grades are calculated according to the following table:
95-100: A
90-95: A-
85-89: B+
80-84: B
75-79: B-
70-74: C+
65-69: C
60-64: C-
55-59: D
Below 55: F
2. The class average total mark and grade should be written at the end of the output file.
3. If the class average is 80% or above your program should display on the screen the message “high average”, otherwise display “normal average.” Use the ternary operator ?: (explained below) for this step.
4. Your program should have a separate function for opening files and another function for closing the files. The function which opens the file takes as input the names (on disk) of the files to open. It returns 0 if the files are open successfully, returns 1 if the input file does not open successfully, and returns 2 if the output file does not open successfully. The function which closes the files takes as input the names of the files (on disk) to close and returns nothing.
Your program should handle the following errors and display a proper error message for each
1. File does not exist
2. Total mark is not in the range 0 to 100

Ternary operator(from MIT OpenCourseWare):
The conditional operator ?: is also another way to evaluate conditions. It operates on three operands, and is thus known as a ternary operator. Here is an example of its usage:
a = x < y ? x : y;
In this example, if the test expression evaluates to true – i.e. if x<y – then the variable a will be assigned the value that the variable x contains. Otherwise, else it will be assigned the value of the variable y.

2. yes we can...

would we? no we would not. Read homework policy

3. please my dear i try it but i had many errors!! please post it now if u can.........

4. You post your effort, and then we can show you where you're going wrong and how to fix it.

5. #include<iomanip>
#include<fstream>
#include<string>
#include<cmath>

using namespace std;

int main()
{
// Declarations
float HW,LT,FL;
float TotalMarks;
float ClassAverage;
string fileName;
ifstream myInFile;
ofstream myOutFile;

// opening the input file which name is given by the user

cout<<" Please, enter the name of the input file: ";
cin>>fileName;
myInFile.open("marks.txt");

//Checking for file opening error

if (! myInFile)
{
cout<<endl<<" Error: Cannot open the input file: "<<fileName<<" !!!"<<endl<<endl;
return 0;
}// end if

while ("fileName.txt")
{
myInFile << Assignment << LabTest >> FinalExam;

}

//calculate TotalMarks

TotalMarks= Assignment + LabTest + FinalExam;
while (myInFile)
{
cout << setw(5) << ID << setw(5) << TotalMarks << setw(5) << Grade << endl;
}

// checking Total marks
if (TotalMarks>100)
{
cout << "Total mark is not in the range 0 to 100" << endl;
return 0
;
}

return 0;

}//end main

i rich this point and i stuck..

please i want u help... as soon as Possible....

6. > while ("fileName.txt")
What is this?
I thought you were reading from marks.txt.

You also need to test a file object, like so
if (! myInFile)
and not a filename (which is basically the same as saying while(true) for details I won't go into)

> myInFile << Assignment << LabTest >> FinalExam;
<< or >>
Choose one.

Take a step back, and try
Code:
```string myWord;
while ( myInFile >> myWord ) {
cout << myWord;
}```
Make sure you can reliably read the file, by printing it straight back to the user.

Now extend slowly to read all your actual data into suitable variables (and print to make sure).

Then start on actual calculations.

7. i change that
while ("marks.txt")
and
myInFile >> Assignment >> LabTest >> FinalExam;

but i have 66 errors ...

and i have to submit after 25min

please if u know it add for me the remains data ...

Thanks

8. Well if you changed something into
while ("marks.txt")
then you didn't understand what the original construct was trying to do.

> but i have 66 errors ...
Did you go back and try the simple things first?

You have to understand how programs are built up. Just giving you the answer will just put this off for another week. Next weeks assignment will be that much harder for you.

With a couple of days to spare, we can usually work through the issues people have.
But if you're basically lost, there isn't anything that can be realistically done in 2 hours.