Thread: Need Help With A Program

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    4

    Need Help With A Program

    I have an assignment that I need help with.

    I need to write a C++ program that will read data from a file, perform computation on the data, then print the result to another file. The data from the file will contian 100 lines where each line contains three items. The three items are an arithmetic operation followed by two integer values (non zero.) The program should perform the arithmetic operation specified on the two integers. Then the program should print out to another file the first number, the arithmetic operation, the second integer, an = sign, then the result of the operation just performed. This should repeat for the 100 lines. The program should compute the result by first using a switch statement to identify the operation (+, -, *, /) then call the appropriate function to perform the computation and print the result to the second file. A sample input file: + 4, 54 - 34 45 * 42 2 / 325 5 A sample output file: 4+45=50 34-45=-11 42*2=84 325/5=13 The general format of the program should be as follows: - The include section... - Declaring the file pointers ifstream infile; ofstream outfile; - The add function - The subtract function - The multiply function - The divide function - The main function
    Last edited by vincex200; 11-29-2007 at 10:30 PM.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    that definitely looks like a straight copy/paste from your assignment sheet.

    if you dont even take the time to type/explain the assignment yourself (let alone post your attemps/errors/sample code/specific questions, etc), then i dont have time to give you an answer.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    4
    Well my group attempted this project and we don't know where to start. Please we need some help asap. PLEASE!!!!

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Heh: I doubt it's a copy-paste job, 'cause that's some really bad arithmetic there.

    Anyway, when all else fails, begin at the beginning. Have you worked out a flowchart, maybe, or at least some basic idea of the overall structure of your program? Does your assignment have some pointers as to what the overall structure of your program should be? (Hint: If I'm asking the question....)

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    4

    Attempted.....

    We tried working on the read data file but that didn't work.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by vincex200 View Post
    We tried working on the read data file but that didn't work.
    Why not?

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    as i said, we wont help if you dont try. if youve 'tried working on the read data', then post your code and any errors if there were any given.

    as tabstop said, the best thing to do is to write out pseudocode for your assignment. that is, ignore programming for the moment. get some paper and write out preciseinstructions on what needs to be done, and in what order. realize that a computer knows nothing--you need to tell it exactly what to do, step by step. so pretend the computer is a child and you need to tell it what to do, that is what you need to write down.

    once you have your 'algorithm', you can start to write the code for it. at least write out the pseudocode and let us know what you have. oddly enough, coding comes second in programming.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    http://www.cprogramming.com/tutorial/lesson10.html
    Happy reading Oh, and it's about File I/O. Might be useful to you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM