473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Program to read grades from file and output average

My group needs help with this program. We attempted to start it and got no where. Please help us.

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
Nov 30 '07 #1
10 5875
671 Expert 512MB
We'd love to help. But...you need to ask a question.
Nov 30 '07 #2
Ok. Where do I start?
Nov 30 '07 #3
671 Expert 512MB
Break down the program into components. For example, there seems to be a component that reads data from the files, another that computes data, and another that prints out the results. Take each component, in a logical order. And then repeat, until you have a component small enough to easily code. Reading from the data file, and printing out the results are small enough. Computing the data needs to broken down.

When writing the code, you should work out the algorithm, before you even start coding.

Start with reading the data rom the file then.
Nov 30 '07 #4
We tried using a program we did long time ago to read data from a file but it wouldn't work. Could you take a look at it and see what may be wrong with it.
Expand|Select|Wrap|Line Numbers
  1. # include <iostream>
  2. # include <fstream>
  3. using namespace std;
  5. int main(){
  6.     ifstream indata;
  7.     indata.open("pmscores.txt");
  8.     char fn[80];
  9.     char mi;
  10.     char ln[80];
  11.     int i,test1,test2,test3;
  12.     double finalscore;
  15.     for(i=0;i<3;i++){
  16.         indata>>fn>>mi>>ln>>test1>>test2>>test3;
  17.     }
  18.     indata.close();
  20.     finalscore=(test1+test2+test3)/3;
  21.     ofstream outdata;
  22.     outdata.open("finalscorespm.txt");
  24.     for(i=0;i<3;i++){
  25.         outdata<<fn<<" "<<mi<<" "<<ln<<" "<<finalscore<<endl;
  26.     }
  29.     outdata.close();
  30.     cout << "Task Completed!"<<endl;
  32.     return 0;
  33. }
Nov 30 '07 #5
Hi Vince,you should follow the expert advice from Oler,just think about breaking down the task into smaller sub task;for example you could start identifying functions that make computations(control), and functions that simply make I/O(boundary) .
Nov 30 '07 #6
oh ok. Well, can you help me with that program above. I just want to make sure that works.
Nov 30 '07 #7
Can you tell us what the program is supposed to do,or at least what you want it to do?thanks
Nov 30 '07 #8
I have to write a C++ program that will read grades from a file on the hard disk drive, compute the average grade and send the result to another file on the hard disk drive.
Nov 30 '07 #9
4,677 Expert Mod 4TB
Does the program above work? Does it not compile? Are you getting output different from what it expects?

PS - This section of our Posting Guidelines was created to help new people formulate good questions - putting all the relevant information into a single post, please have a look at it. Thanks
Nov 30 '07 #10
The program does not work. It will compile but give 3 repeated answers from the txt file. I need it so that it gives me it only once and shows that other info on the txt.
Dec 1 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

by: hjc | last post by:
i am trying to created a program that will write a grading program for a class with the following policies there are 2 quizzes each graded on the basis of 10 points there is 1 midterm and 1...
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
by: sparkid | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
by: spike29 | last post by:
write an application in Javascriopt that will process peoplesgrades Each person has 4 test grades and you are to compute the average for each sudent. The input will include: 1. student name -...
by: gdarian216 | last post by:
I have written a c++ program that takes input from a file and outputs the average. The program uses structs and I need to convert the struct to a class. I just dont know how to get started and if...
by: gdarian216 | last post by:
the program reads input from a file and then outputs the averages and grade. for some reason it is reading in the same line twice and it doesn't print out the grade. everything else is correct, if...
by: gator6688 | last post by:
I have to write a program that allows the user to enter the information for up to 20 students. The info then has to be displayed and written to a file. After I enter the first students info and hit...
by: Sleepwalker817 | last post by:
Hello, I am trying to create a program that is supposed to calculate and print the average of several grades entered by the user. The output is supposed to look something like this:...
by: xtheendx | last post by:
I am writing a gradbook type program. It first allows the user to enter the number of students they want to enter. then allows them to enter the first name, last name, and grade of each student. The...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.