Thread: C++ Question

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    C++ Question

    I have this assignment that I really need help on. The assignment is as follows:

    "The final exam in a class consists of 30 multiple choice questions.

    INPUT-The first data line contains the key to the exam. The correct answers are the first 30 characters; they are followed by an integer number that says how many students took the exam (call it n). The next n lines contain student answers in the first 30 character positions, followed by the student name in the next 10 character positions.

    OUTPUT-For each -the student's name; followed by the number of correct answers; followed by PASS if the number correct is 60 percent or better, or FAIL otherwise."

    I looked through the textbook and it didn't help. Could anyone help me out on how I write this program. Thanks.
    Last edited by congo kong; 10-21-2005 at 08:56 PM.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    C++ answer:

    Begin at the beginning.

    1) Post what you think the Input will look like.
    2) Post what you think the Output will look like.

    3) Write a simple program to read in one line of data from a file into a string type variable, and then display the string to the console window. If you haven't done file input/output yet, then prompt a user to enter their name, and then display their name to the console window. Post your code.
    Last edited by 7stud; 10-21-2005 at 09:42 PM.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    4
    I honestly don't know how to do it. For the input I think I need to put in abcd... as the correct answers, along with the number of students taking the test (which I would say 10), and then the answers of the students.

    For the output I'm guessing I need an if statement like
    Code:
    if (x>59) 
    {
    cout<<"PASS";
    }
    else
    {
    cout<<"FAIL";
    }
    I don't have any examples to use as resources (nothing in the book relates to this).
    Last edited by congo kong; 10-21-2005 at 10:04 PM.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I honestly don't know how to do it. For the input I think I need to put in abcd...
    I'm not asking you to write any code. Post exactly what a line of input will look like. And, post exactly what a line of output will look like.

    Have you learned about file input/output or are you supposed to use console window input and output?

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    4
    The way we input and output is by writing in the source file:
    Code:
    cout<<"...";
    cin>>"x";
    Once I configure, build and execute the program a window comes up where they ask me what I typed in the cout. I type in what I want and that's the input (like x). I'm not sure if that's any help. I use Microsoft Visual C++ 6.0. The teacher doesn't have any specific preference on what type we use because we do all the assignments outside of class. I think this is console window input and output.
    Last edited by congo kong; 10-21-2005 at 10:20 PM.

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    My 2 cents worth:

    If you try to do this using keyboard input you're going to do an awful lot of typing; every time you try to run the program while debugging it, you will have to type in all that input.

    I suggest you start by writing your input in a text file. Then read in your textbook about how to get input from a file. File input is not much harder to program than keyboard input, & starting this way will help you think about what to do next.

    Then start by writing a program that reads the input into ... [how do you think you should store the input in your program?].

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    4
    How would I write this input? The biggest problem is I don't know where to start. I don't know what to type that would basically judge how many answers are correct for each student based on an answer key.

  8. #8
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    You dont have a sample Input or Output? Its really hard to analyze the problem with out the sample. Your prof must have shown you something.

    But analyzing the problem gives me a picture thet the input and output would look like this..

    Input:

    Code:
    abdcedacbdbdbabdbebdbabdbabdeb12 // First line contains the correct answers.
    Followed by the number of students who took the exams.
    Which is 12 students.
    
    Then in the next lines it would accept 12 inputs. That is 12 students exam results.
    abddbdbdbdabdName Here
    asdasdsadasdasName Here
    Output would look something like

    Code:
    Student Name 25 PASS //Stud name then, Number of correc answers. Then PASS or FAIL
    next student here..
    Next student here..

    You must come up with something first before we could answer some of your questions. They dont encourage us here to do someones Homework here.

    You can use declare a string variable. And use a str_pos or substr(what ever it is) method in it. This wouldnt be hard to make.
    Last edited by loko; 10-22-2005 at 06:36 AM.

  9. #9
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    You dont have a sample Input or Output? Its really hard to analyze the problem with out the sample. Your prof must have shown you something.
    Huh? The instructions describe the exact input and output. Unfortunately, the poster thinks the "input" and "output" is C++ code

    input: what the assignment wants you to type in, which your program will subsequently analyze. If you can't figure that out, you are dead in the water.

    output: what the assignment wants you to display after your program analyzes the input. Once again, you have to figure that out before you can proceed.

    Then the assignment will require that you know:

    1) How to read input.
    2) What an array is and how to access the elements of an array.
    3) What a string is and how it can be treated as an array.
    4) How to display the output.
    Last edited by 7stud; 10-22-2005 at 02:18 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM