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

This is a discussion on can u solve for me this Question please in 2h??? or sooon?? within the C++ Programming forums, part of the General Programming Boards category; Write a program that reads a list of students marks in a course from an input file then calculates the ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    6

    Unhappy 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. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    yes we can...

    would we? no we would not. Read homework policy
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    6
    please my dear i try it but i had many errors!! please post it now if u can.........

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    You post your effort, and then we can show you where you're going wrong and how to fix it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    6
    #include<iomanip>
    #include<fstream>
    #include<string>
    #include<cmath>

    using namespace std;

    int main()
    {
    // Declarations
    float HW,LT,FL;
    float TotalMarks;
    float ClassAverage;
    string ID, Grade , description;
    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
    // Reading marks

    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. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > 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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Apr 2011
    Posts
    6
    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. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me solve dis question..Please
    By imbax in forum C Programming
    Replies: 2
    Last Post: 09-23-2010, 09:25 PM
  2. Help to solve question, am revising for exam
    By Samuelson in forum C Programming
    Replies: 2
    Last Post: 06-18-2010, 04:52 AM
  3. how to solve this question?
    By zcrself in forum C Programming
    Replies: 9
    Last Post: 03-09-2010, 11:12 PM
  4. C bufferoverflow question. can anyone solve it?
    By asdfgh in forum Linux Programming
    Replies: 2
    Last Post: 11-03-2009, 12:40 PM
  5. a question that i can't solve
    By revolution3396 in forum C Programming
    Replies: 16
    Last Post: 11-19-2008, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21