C++ :: Read Data From A File - Show Max And Min From Scores

Feb 26, 2013

My program reads data from a txt file and it displays the test scores and the sum of the scores, and it also shows the max and min from the scores , so far only one number shows up from the scores instead 10 and i think my sum is wrong too, but i cant get the max and min to work ...

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void openfile(ifstream &infile);

[Code] .....

View 17 Replies


ADVERTISEMENT

C++ :: Read Scores From File And Displays All The Scores

Aug 19, 2014

Okay so suppose that a text file grade.txt contains an unspecified number of scores. How would I program that reads the scores from the file and displays all the scores, their total and average? Scores are stored in the format of one score per line. Im having trouble with the whole #include <fstream> file and how to lay it all out in visual studio.

View 1 Replies View Related

Visual C++ :: Get Program To Read From File Of 15 Scores?

Dec 10, 2014

I'm trying to get the program to read from a file of 15 scores. 10 are quizzes 5 are exams. I want my program to read from the input file the first name "or" last name and if the user puts a different name, the program Gives off an error screen message

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
const int NUM_STUDENTS = 20;
const int NUM_QUIZZES = 10;
const int NUM_EXAMS = 5;

[code]....

View 14 Replies View Related

C++ :: Get Scores From Admin And Sort Them Ascending Then Show Middle Score

Nov 23, 2013

I program a software to get scores from admin and sort them ascending then show the middle score(if admin enter middle).but when i compile it nothing happen.what should i do?here's code ,i use dev compiler

Code:
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main(int argc, char *argv[]) {
int counter,j,count,counter2,m;

[Code] ....

View 14 Replies View Related

C :: Read Text From A File And Show What Words Occur How Many Times

Apr 21, 2013

I'm trying to make program that will read text from a file and show what words occur how many times. I'm trying to make it so that if a new string comes, it saves it into wlist[], and counts 1 to wcount[]. If the same word is there, it will just add 1 to wcount[]. The program will end when it gets to the end of a file.

I don't know the reason, but I can't get strcmp and strcpy to work. I had to put a pointer in curword, just to make it compile.

Code:
#include <stdio.h>
#include <string.h>
#define LIST_MAX 100
#define WORD_MAX 20
int main(){

[Code] ....

View 6 Replies View Related

C/C++ :: Function To Read Scores Into Array?

Apr 16, 2015

I am currently in a beginner C programming class. I have written most of my code and the problem that I am running into when i compile and run the code. I am able to input more than required scores for input. I think my code is wrong from line 126-136. The program runs fine with no errors. I'm just unable to input the required number of scores allowed.

/*************************************************************************
* A program to calculate grade.
*************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

[Code].....

View 2 Replies View Related

C :: How To Read Data In A File And Print It Then Copy Contents To A File

Mar 8, 2013

Code:

#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
char buffer[256];
FILE * myfile;
myfile = fopen("read.txt","r");

[Code]...

I also got an error in printing wherein the data in read.txt is "Hello" newline "World" and my program prints world twice.

View 3 Replies View Related

C++ :: How To Read Data From TXT File Into Array

Feb 25, 2013

I wanna read a txt file like this
1.00518 2.01903 3.01139 4.01343 5.02751 5.99913 7.00011 7.99851 .....
and fill the array P[i][j] with the data.

I try to use

if (myfile.is_open()) {
//for (int i = 0; i < 1; i++)
//{
getline (myfile,DMArray[0]);
cout << DMArray[i] << endl;
//}
myfile.close();
}

But this read the data into a string. How should i do with this string. Besides I know the dimension of the data I am reading.

View 1 Replies View Related

C++ :: Using Loop To Read In Data From A File?

Oct 30, 2013

My function is only reading the first line of numbers even though I have the loop to keep returning to it in main(). How do I have it read from the file until it runs out of data to retrieve?

File being read

90 83 94
72 65 81

File being sent the data(Only the second average is correct, working on the first)

Student Information
Student IDGradeAverageLetter Grade
1895612
90 83 94
289
90 83 94

#include <fstream>
#include <iostream>
using namespace std;
ifstream infile;
ofstream outfile;
void grades(int&,int&,int&); // Grades from the input file
int myavg(int,int,int); // Calculates the Average of the 3 grades

[Code] .....

View 8 Replies View Related

C/C++ :: Read Bytes From A Data File

Dec 5, 2014

I am a member of a group still developing the Microprose European Air War game. We have the source code and permission to do this. As the code dates back to 1998 I use Visual Studio 2006.

I have written many programs in Visual basic, and have the following one to read the airbase value in the "targets.dat" file. The file has a four byte header containing the number of tatgets, and a 32 byte data block containing the data for each target.

Private Sub Command1_Click()
List1.Clear
Dim nt As Long
Dim a4() As Long  
Open App.Path & " argets.dat" For Binary Access Read As 1
'read and display the number of targets  

[Code] ....

Despite many attempts I cannot write the C equivalent of this code into the eaw.exe source. All I really need to know is how to open the 'targets.dat' file and how to get the value of a byte (or integer, or long) at a given position as in the "Get #1, k, a4(n)" line.

View 1 Replies View Related

C :: Read Link List Data From File

May 7, 2013

i write this program and every things work correct except when i want to add data of file to the link list .when i add the data to the link list by add_to_linked_list() every things work correct but when i use read_linked_list_from_file() it doesn't work

Code:

#include <stdio.h>
#include <stdlib.h>
// double linked list structure
struct linked_list {
struct linked_list *next;
struct linked_list *prev;
char *value;
};

[code]....

View 2 Replies View Related

C++ :: Read A File Into 2D Array And Display Data

Nov 15, 2014

I am currently working on a problem where I read a file into a 2D array, and display data. If you saw my code earlier, this is the same problem, but I am now further along.

The file (90 characters) looks like this:
S
R
R
S
R
R
R
R
S
S
....

The "R" resembles rainy days, the "S" resembles sunny days, and the "C" resembles cloudy days. There are 90 characters in the file. The first 30 are for the month of June, the next 30 are for the month of July, and the last 30 are for the month of August. The 31st day of the months are NOT included.

I read the data into a 3 x 30 array, where the row indicates the month (0 = June, 1 = July, 2 = August) and the column indicates the number of days in each month.

Now I need to create a function that creates a report and displays, for each month AND for the whole 3 month period:
1) The number of rainy days
2) The number of cloudy days
3) The number of sunny days
4) Which of the 3 months had the largest number of rainy days

Here is my code so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int MONTHS = 3;//Number of months

[Code] .....

There are no compiling errors, but I am not getting the data I want. My rCount and cCount variables end up being 0, and my sCount variable is 90.

View 4 Replies View Related

C++ :: Read From A File And Place Data Into Array

May 3, 2014

Assume you want to read from a file and place the data from the file into an array. The array can hold 10 integers. The file may contain any number of integers with 1 integer per line. Fill in the missing loop test condition so that we will read from the file until either end of file occurs or the array is full. Note we are using cin to read from the file since input redirection is being used.

cin >> temp;
arrayIndex = 0;
while ( _____________________________________) {
array[arrayIndex] = temp;
arrayIndex++;
cin >> temp;
}

View 2 Replies View Related

C/C++ :: Read A Line With 8 Bytes Of Data From A File

Jul 23, 2012

How to read a line with maximum of 8 bytes from a line in a file.

Let say line has 10248 bytes in one single line and same repeats for remaining lines in the file.

I need to read the first 8 bytes of a line and go on read the last 2 bytes of the line and repeat the till end of file.

View 3 Replies View Related

C++ :: Not Able To Read Data From Text File And Convert It To Integer

Mar 25, 2013

I am trying to read an array values from Tmin.txt file. I take array size from user viz. number of raw & column and then, read the following data from Tmin.txt file which look like this:

20 40 20 25 30

20 30 40 20 25

20 40 20 25 30

20 30 40 20 25

30 40 40 30 40

I am using getline, and then converting it to int by using atoi. But my code is not working.

Code :
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code] ....

View 10 Replies View Related

C :: Read Data File And Emit Various Bits Of Information

Mar 31, 2014

For my intro to c programming class, our homework requires us to read a data file and emit various bits of information. the data file looks like this

#Domain: the URL
#Alexa: some kind ranking, small numbers are better
#Rank: another sort of ranking, big numbers are better

#Domain Alexa Rank Site Name
#------------ ----- ------- ---------
amazon.com 13 1177136 Amazon.com
google.com 1 4533883 Google
youtube.com 3 3637788 YouTube

[Code] ....

I've started and am able to get the correct number of lines, and the alexa number, but I keep getting some errors and am just unsure where to correct my code. This is what it looks like;

Code:
// Lexi Anderson
//CS 156
#include <stdio.h>
int main() {

[Code] .....

and once compiled, I get errors.

View 7 Replies View Related

C :: Unable To Read Data From Text File And Print It

May 12, 2014

I am having trouble in reading data from my text file and print it out exactly like how it looks like in the text file. The problem im having is it will not read the last y Coordinates of the point. it keep reading the second last point for y coordinates which is wrong.

my text file is
0.0 0.0
0.0 1.0
1.0 0.0(but it read until here)
0.0 0.0(suppose to read the last point which is here)

For your information, this is my 1st year degree assignment in C programming. It is to create a program which can read text file (manually create) and print it out in a program and calculate the area for the polygon using ADT function ( .c and .h files)

*This is the code for my read file function*

Basically this accepts a Polygon and a file pointer as parameters. It reads the polygon point data from the file, pass the read data to plg_new() to create a new Polygon and returns the new Polygon created.

Code:

polygon *plg_read(polygon *New_polygon, FILE *Coord) {
int i;
int numberofvertices=0;
int count=0;
char filename[50];
double xCoor[50], yCoor[50];

[Code]....

This is the second function my polygon new code. This ADT function basically creates a new Polygon with malloc(), initialize all ADT data members with its parameter values and returns the Polygon.

Code:

polygon *plg_new(double *xCoordinates, double *yCoordinates, int numberOfVertices) {
int x;
polygon *New_poly = (polygon *)malloc(sizeof (polygon));
if(New_poly->xCoordinates == NULL || New_poly->yCoordinates == NULL) {
free(New_poly);

[Code]....

This is the rest of the code if you need to refer to other codings.

Code:
/**
*@file polygon.c
*@brief Functions for polygon / Struct has polygon numberOfVertices, polygon *xCoordinates and polygon *yCoordinates
*@author: Tan Xian Yao
*@id: 4323440
*@date: 22/04/2014
*/

[Code]...

View 6 Replies View Related

C++ :: Unable To Read Data File From Two Dimensional Array

Apr 27, 2014

I am new to C++ and I am having an issue reading in a 2 Dimensional array from a data file. I am very close to reading it in perfectly except for one issue, the loop is ignoring the first value from the data file.

This is the code I have so far:

#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <functional>
#include <conio.h>
#include <iomanip>
#include <string>
#include <fstream>

[Code]...

This is the values from the data file:

300 450 500 210
510 600 750 400
627 100 420 430
530 621 730 530
200 050 058 200
100 082 920 290

When the Program shows my array it comes up as:

450 500 210 510
600 750 400 627
100 420 430 530
621 730 530 200
050 058 200 100
082 920 290 0

Every array location is moved up one, like the program just completely ignored the 300 at the beginning.

View 1 Replies View Related

C++ :: Read Input File Of Data And Store Them In Arrays

Nov 5, 2013

Read the input file of data ( employees.txt) and store them in arrays. This company can have up to 55 employees [b]i need to do these following in these program:

Write a function to read the input file and store the data in arrays.
Write a function to calculate regular pay.
Write a function to calculate overtime pay
Write a function to calculate gross pay.
Write a function to bubble sort the employees into order by last name, first name.
Write any swap functions that are needed.
Write a function to write output to a file called payroll.txt

Format of file is EMPLOYEES.TXT[/b]

Hours Pay Rate Employee Number First Name Last name
40.0 10.00 A1234 Jane Adams
50.0 10.00 L8765 Mary Lincoln
25.5 10.85 W7654 Martha Washington
52.0 15.75 A9876 John Adams
45.0 25.00 W1235 George Washington
40.25 55.00 L9087 Abraham Lincoln
30.0 9.75 T9876 William Tell
42.5 12.50 M7654 Missy Muffett
30.0 10.00 P8765 Peter Piper

HERE IS MY CODE SO FAR:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void tellUser();

[code]....

View 9 Replies View Related

C++ :: Sort Data From Text File Into Array As Its Being Read?

Feb 12, 2013

I am suppose to make a program that reads in data from a text file (integers only) and sorts them as it inserts them into an array of size 10. I did this using an insertion sort, which worked great. But now I am being told that I need the function has to read ALL of the numbers in the text file, not just the first 10, and I am not allowed to store them THEN sort, it has to be sorted as being stored.

This is what I have for sorting first 10

void sortArray(int iArray[])
{
string fileName = "";
fstream inFile;
int tmp = 0;

[Code]....

View 3 Replies View Related

C/C++ :: How To Reuse Existing Code To Read Data File In Qt

Aug 13, 2014

I've got some code in C++ that does some basic analysis on price data and I run it from the cmd prompt. One of the functions I had built to read in the data is as follows:

void ReadPricesFromFile(constchar*filename,std::vector<PriceInfo>&prices)
{std::ifstreaminput(filename);
input>>prices;}

How would one merge this type of code into a Qt GUI? Ideally, I'd like to use something like QFileDialog to open up a folder with my data files, select a file, and then read the file that the user selects. Would the main.cpp look something like this?

int main (int argc, char *argv []) {
QApplication prog (argc, argv);
QPushButton *load_button = new QPushbutton ("Load File");
QObject:: connect (load_button, SIGNAL (clicked()), &prog, SLOT ( (ReadPricesfromFile function?);
load_button-> show ();
return prog.exec ();}

View 3 Replies View Related

C# :: Read Data From More Than One File At Once - Not All Code Paths Return A Value

Apr 11, 2015

I am trying to read data from more than one file at once. The files are different types e.g. one is a text file one is an xml file like so, StudentInformation.txt, CollegeInformation.xml. The files are all stored in one place, in this case on the D drive of a local computer. I am trying to locate any files in the D drive with a file extension of .txt or of .xml (there may be more than two of these files in the future, so I'm trying to allow for that). Then I want to open all of these files, extract the information and output all the information in one display window. I want all the information from these two or more files to be displayed together in the display window.

Here is the code so far. It is throwing up errors.

//Load from txt files
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
IEnumerable<string> fileContents = Directory.EnumerateFiles("D:\", "*.*", SearchOption.TopDirectoryOnly)
.Select(x => new FileInfo(x))
.Where(x => x.Extension == ".xml" || x.Extension == ".txt")
.Select(file => ParseFile(file));}

[Code] ....

The error it throws up is:
Error 1 'BookList.Mainwindow.ParseFile(System.IO.FileInfo)': not all code paths return a value

View 2 Replies View Related

C# :: Combine Query To Show All Data

Sep 22, 2014

So I've been working on this for awhile and FINALLY got it to work. This is my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

[Code] ....

As you can see I will have the Name and total right next to eachother.. Problem is I dont want to make a million MySQLCommands for each ID.. Is there a Way I can list all data in each label?

For instance the Select from Text will show all the text from each different ID
and the Select from STOCK-USED as total will show all the total for each ID

Instead of having to list them individually.

Even if I leave it to this

"Select text FROM `parts`";

It selects the 2nd ID in my database and displays its text.. Forgets about the first one completely ...

View 2 Replies View Related

C :: Program To Read Binary Data And Print It - File I/O Error

Mar 14, 2013

Objective of this program is to read binary data from a file and print it.

Code:
#include <stdio.h>
void readFile(void);
int main(){
readFile();
return 0;

[Code] .....

But When I Run This Code First It Print "Error." Then Rest Of The File.Say In My File I Have "I AM HUMAN", It Prints "Error. HUMAN"!!

I Cant Figure Out Whats Wrong In The readFile() Function.It seems right to me.

View 4 Replies View Related

C :: Read Specific Amount Of Data From File Until Terminating Set Is Reached

Jul 23, 2014

I wrote a code to read a specific amount of data from file until terminating set is reached. however the code does what its supposed to correctly until it reaches the 5th loop it justs stops responding. I've checked the reading file and all elements are correct in the file.

Code:
int main(void){
FILE *file1;
FILE *file2;
FILE *file3;

struct t test1;
struct t test2;

[Code] ....

Screenshot of program crashing:

Screenshot of reading file:

View 11 Replies View Related

C++ :: Open A Text File Then Read Data And Print It Back?

Nov 5, 2013

I am in an "intro" C++ course and am having trouble with a section of my current project.

We are required to open a text file, read the data from that file, and print it back.

However, we are supposed to let the user input the name of the file that is to be opened. This is the code I have so far. It is not opening anything.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int NUM_QUESTIONS = 30;
typedef char CharArray[NUM_QUESTIONS];
string fileName;

[Code]...

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved