473,503 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program to read grades from file and output average

6 New Member
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 5898
oler1s
671 Recognized Expert Contributor
We'd love to help. But...you need to ask a question.
Nov 30 '07 #2
vincex200
6 New Member
Ok. Where do I start?
Nov 30 '07 #3
oler1s
671 Recognized Expert Contributor
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
vincex200
6 New Member
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;
  4.  
  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;
  13.  
  14.  
  15.     for(i=0;i<3;i++){
  16.         indata>>fn>>mi>>ln>>test1>>test2>>test3;
  17.     }
  18.     indata.close();
  19.  
  20.     finalscore=(test1+test2+test3)/3;
  21.     ofstream outdata;
  22.     outdata.open("finalscorespm.txt");
  23.  
  24.     for(i=0;i<3;i++){
  25.         outdata<<fn<<" "<<mi<<" "<<ln<<" "<<finalscore<<endl;
  26.     }
  27.  
  28.  
  29.     outdata.close();
  30.     cout << "Task Completed!"<<endl;
  31.  
  32.     return 0;
  33. }
Nov 30 '07 #5
MarshMallow
52 New Member
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
vincex200
6 New Member
oh ok. Well, can you help me with that program above. I just want to make sure that works.
Nov 30 '07 #7
MarshMallow
52 New Member
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
vincex200
6 New Member
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
sicarie
4,677 Recognized Expert Moderator Specialist
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
vincex200
6 New Member
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

4
12961
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...
21
2512
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...
1
3551
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...
3
2477
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 -...
9
3388
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...
2
2189
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...
1
1790
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...
1
1592
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:...
14
8007
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...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1516
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.