C/C++ :: Display Data From File Into 2D Array - Print Closest Bmi From Data

Mar 28, 2015

#include <iostream>
#include <fstream>
using namespace std;
int main() {
int r = 0;
int c = 0;
int num[17][15] = { 0 };
[Code] ...

// Here is my code for displaying the data from the text file into a 2d array and height next to it, but I am not able to diaplay the height from 60 to 76 next to the row of the 2d array, as shown in the table below. This is my program:

Recently the health authorities have listed a new way to calculate the body mass index (BMI) of an individual.
Values of 20 – 24 are classified as normal, 25-29 as overweight, and 30-34 as heavy.

The table below is a portion of a typical BMI table.

BMI:202122232425262728293031323334
Height:
60102108113118123128133138143149154159164169174
61106111116122127132138143148153159164169175180
.
.
.

MY task is to write a program that does the following things:

1.Produce the table by reading in the data from bmi.txt (on Moodle) into a 2-D array.

2. Display the table neatly on the screen, with row and column headings. The BMI should go from 20 to 34. The height should go from 60 to 76 inches.

3. Prompt the use for their height (in inches) and their weight.

4. Make the program print the closest BMI.

If their weight is lower than the values on the table, use 20 as the BMI.
If their weight is higher than the values on the table, use 34 as the BMI.

5.Loop the program so the user can find more BMI’s.

View 7 Replies


ADVERTISEMENT

Visual C++ :: Finding Value In Data File Closest To Calculated Data?

Jan 11, 2014

I'm reading from a file the middle column of data (Volts) where my test file "AP.txt" is opened by my program. Here is a segment of the data:

time Volts dV
49552 -66.20183 -0.01556807
49553 -67.76025 -0.01556495
49554 -69.30704 -0.01533247
49555 -70.81799 -0.0148486
49556 -72.26774 -0.0141133
49557 -73.63226 -0.01315276
49558 -74.89141 -0.01201764

Since the calculation I performed gives me -71.77 Volts, I need to match this value to the time that this occurs closest to using my program, and output the time that this occurs at.

Here is my program so far:
int main()
{
std::ifstream inFile;
inFile.open("AP.txt");
ofstream results_file ("maxvaluewithinput.txt");
float TimeAtdVMax = 0;
float VoltsAtdVmax = 0;

[Code]...

If you're curious, this program isn't for homework. It's part of the independent learning on C++ I'm doing for a Master's Thesis; the program will eventually model the APD90 of a ventricular action potential.

View 10 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 Data From File Then Make It Into Array Of Structures And Print Afterwards

May 13, 2012

I am trying to read from a data file that has input as :

12.0, 11, 123
14.0, 12.1, 3

And I want the program to read the data from the file and then make it into an array of structures and then print that array afterwards.

Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_INPUT 1000
int n =0;
int i = 0;
typedef struct {
double x[MAX_INPUT];

[Code] .....

The program when run gives the following output:

Ishtiaque-Mohammed-Khans-MacBook-Pro:Comp20005 IshtiaqueMKhan$ gcc -Wall -ansi -o ProjectB ProjectB.c
ProjectB.c: In function "main":
ProjectB.c:59: error: incompatible type for argument 1 of "print_array"

View 1 Replies View Related

C :: How To Display Data From A File

Feb 24, 2013

I'm trying to display data from a text file named ace_data.txt. Here's a preview of the first three lines i want to display:

2001 106 15
2002 65 12
2003 175 16

So basically, here is what my code looks like...

Code:
#define FILENAME "ace_data.txt"
int main (void) {
FILE *inp,
*outp;

[Code] ....

And nothing is displayed when i run the program. I feel like I made some mistake with the fopen() and fscanf() functions but I'm not so sure how to correct them.

View 4 Replies View Related

C/C++ :: Print Output With Append Data In TXT File

Oct 22, 2014

I was recently introduced to the fstream header file. I want to know is their a easy way to print an output with append data in a .txt file.

And secondly I am also having an error with my header file. It says error: cannot open source file "fstring" when I hover my mouse over "#Include<fstring>".

View 7 Replies View Related

C :: Cannot Display Data Written To File In Switch Statement

Mar 18, 2013

i cant display the data written to this file in a switch statement (case 2) what am i doing wrong..the file data is being written into the text file but i cant display it

insert
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
FILE *fp; //creates a file pointer
typedef struct date_info

[Code].....

View 8 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 :: 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

Visual C++ :: Display Data Of Text File In List View

Sep 24, 2012

I want to display data from text file in list view and in tree view root will be file name, but i dont know how to do it, the problem is with displaying text file data in list view, i don't know anything about that. text file data is very simple. It is just a square matrix of double values like:

21.06 34.06 5.0
12.78 45.25 6.9
12.89 45.98 5.5

in list view i want to display it.

View 14 Replies View Related

Visual C++ :: Program To Display Values From Data File As Image?

Jul 29, 2014

I am writing a program to display values from a data file as an image. But I can only get a blue screen. Here is a small program resembling my code. what I have missed? I only changed OnDraw function.

Code:
void CColorDisplayView::OnDraw(CDC* pDC) {
CColorDisplayDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect rect;

[code].....

View 10 Replies View Related

C++ :: Read Data From A File Then Store / Search And Display Using Classes And Arrays

Apr 12, 2013

A company uses two text files: one to store employees' details and another to log their sign in/out time.

The details file - called details.txt" has the following format: ID, Name, Date of Birth, SSN, Department, Position - separated by spaces.

An extract from the file looks like this:

10 alice 4/23/1972 123-45-6789 support assistant
3 bob 6/7/1980 111-12-1134 logistics manager
1 carol 10/2/1963 987-123-1143 admin ceo
2 dave 10/3/1974 902-22-8914 admin cfo
17 erin 6/13/1991 126-83-1942 technology supervisor
15 frank 2/22/1987 303-12-1122 logistics assistant

"timelog.txt" contains daily logs of when employees arrive and leave. It has the following format: ID, Date, Arrival Time, Departure Time - separated by spaces. An extract from the file looks like this:

10 2/11 0900 1700
3 2/11 0930 1730
1 2/11 1100 2000
2 2/11 1000 1530
17 2/11 0900 1700
10 2/12 1000 1830
3 2/12 0930 1730
1 2/12 1100 1900
2 2/12 1030 2000
17 2/12 0900 1700
15 2/12 1100 1600

I have to write a program that searches for specific records using some search parameter, and displays them. Ok first i have to read the data from the files and store them. this is what i have so far....

#include <iostream> //Accesses libaries for console input and output
#include <fstream> //Needed to access the fstream object to read files
#include <string> //Needed to access the string class
#include <cstdlib>

[Code] ....

I know my class and array code is totally wrong i dont know how to store the data for the info is in integer and string form... do i use strings, arrays?

View 1 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++ :: 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

Visual C++ :: Use For Loop To Read Certain Data From Txt File And Print To Console

Sep 28, 2014

I'm new to programming and i'm trying to do a certain task. I want to use a for loop to read certain data from a txt file and print them to a console. I'm trying to read student names and their grades.

Something like
3 // 3 represents the number of students.
George 97
Sarah 70
Maya 88

The data may vary but it's always in this format.

View 14 Replies View Related

C :: File Operations - Fwrite Padding Extra Data In File Compare To Data Provided As Input

Oct 28, 2014

I am trying to write my files to another subfolder . Below is my program.

Code:
cat th6.c
#include <pthread.h>
#include <stdio.h>
#include <string.h>

#define SIZE 8
#define NUMELM 8

[Code] ....

I observe my filename along with directory as text in the new file created in sublfolder. This is output.

[cporgs/apue/threads]: mkdir first
[cporgs/apue/threads]: ./a.out test.txt first
test.txt -- first/test.txt
dfdfdfdfdfdfdf-14
dfdfdfdfdfdfdf-14
in thread test.txt first
[cporgs/apue/threads]: cat first/test.txt
dfdfdfdfdfdfdffirst/test.txt
[cporgs/apue/threads]: cat test.txt
dfdfdfdfdfdfdf

I could not able to get from where this filename and folder is getting added.

View 4 Replies View Related

C :: Store Data In Binary File Then Use It To Find Inverse Of Matrix Form Of Data

Dec 6, 2013

I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.

Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();

[Code] ....

View 4 Replies View Related

C++ :: Data Input Into A Text File While Not Deleting Original Data

Apr 19, 2013

I want to input data into text file while not deleting the original data in the file and I use something as

ofstream writefile;
writefile.open("example1.txt");
if (writefile.is_open()) {
for(j=0; j<N; j++) {

[Code] ....

But this will delete the original data.

View 3 Replies View Related

C++ :: Getting Data From Excel - CSV File Or Data Library?

Jan 30, 2013

I am very very new to C++. A bit of background. I have been writing in excel vba for large number crunching, and the code is now taking quite a while to run. A friend of mine suggested i start writing in C++, so i read up on it. And downloaded Code:Blocks.

My VBA Code is:

Sub arrayss()
Dim NameArray As Variant
Dim datarray As Byte
Dim DirectionArray As Variant
Dim WinArr As Variant

[Code] .....

Ultimately i would like to recode this to C++, but my first and probably silly question is how do i get the data from Excel to use in C++. I was thinking either to put the data in 3 csv files and convert into three Arrays in C++. Or maybe create a library of the data in C++. Ultimately it is speed i am looking for, so before i start recoding i wanted to start with the best way.

The data is like this in excel: (don't know how to create a table)

ABC DCA GFE THE
15 0 1 0 1
30 1 0 1 0
45 1 1 0
00 0 0 1
15 1 1 0
15 1 0 0 1
15 0 1 1 1
30 1 0 0
45 1 1 1

So the headers would be in one array, the 15's, 30's etc would be in another array and the 1's and 0's and Empty ( i need it to record an empty cell) would be in another array...

View 14 Replies View Related

C++ :: Data From TXT File Into Array

May 14, 2013

#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <stdio.h>
#include <ctype.h>

[Code] .....

LA .20 45
ME .15 90
MD .15 90
MA .20 90

Fairly simply BAC calculator, and I am trying to get data from a text tile, which you can see a sample of just below the code. I am attempting to store the information in an array which can be displayed with the final calculation. It compiles fine, but when I get to the part where I enter the state, I get nothing back.

View 4 Replies View Related

C++ :: Data From File To Array

Jul 24, 2013

I have names in a text file followed by three scores. I have tried and tried to get this to work but im totally lost. I need to take the names and store them into an array, and then take the three scores after the names and store then into a separate array. Then I need to output the information into a table like this:

name score score score
name score score score
name score ..... etc....

I have tried...

A loop to iterate 11 times for the 11 bowlers. each time it iterates i use getline to store the name into array[index] and then use a nested loop with myfile >> array2[index2] to store the scores. Its not working when i use a test loop to display each index in either array.

View 1 Replies View Related

C/C++ :: Using Data File In Array

Jul 6, 2014

I am trying to make a function that uses an array from a data file. I idea is a user inputs a number and if it matches one in the data file they will get access. I can make a function that opens the file, but returns 0. So all the user has to do is enter 0 and they get access. None of the numbers from the file come into play. I have tried turning a string into an int but that did not work. Now trying to figure out how to pass an array in a function. Here is what I have so far:

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int mySequentialSearch(int array[],int size)

[Code] .....

View 1 Replies View Related

C++ :: Data From Txt File Into Array?

Nov 27, 2012

When I try an put the input data into an array it crashes my program. I can put it into a single string but not an array of strings... This is needed so I can bring all the data in to compare it and rearrange it.

Data format in file;

NAME5006
NAME3050
NAME3213

These are highScores for a game I am currently making. I want to rearrange them so they can be output in order on the highscore page.

Code:
#include <string>
#include <iostream>
#include <fstream>
#include <math.h>
#include <sstream>
string scoresort[9];
int HighScore(int PlayerScore){
int x;
fstream scorefile ("scores.txt");

[code]....

View 1 Replies View Related

C :: Reading Data Into 2D Array From A File

Apr 29, 2013

I'm having issues reading to a 2d array from a file. When I try to read the data from my file into my matrix variable it simply doesn't read anything and leaves the variable unmodified. I've tried just reading the first piece of data in the main function and it doesn't work there either. I'm really perplexed at this point since I've never had an issue reading from a file before. Here's my relevant code:

Code:
int main(int argc, char** argv) {
double matrix[MINSIZE][MINSIZE]={0}, vectors[MAXSIZE][MINSIZE], ans[MAXSIZE][MINSIZE];
FILE * inFile;
inFile = fopen(FILENAME,"r");
if(inFile==NULL){
printf("File does not exist.

[Code] .....

View 4 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/C++ :: Loading Int Data From File To 2D Array

Apr 28, 2014

Heres what I am suppose to do, So it doesnt seem hard to understand my messy code!

1. Gotta load the file "FactoryData.txt"
2. Load all values in my 2D array (array[5][3])
3. Print out the array to ensure that the copying went by well.

Heres my problem:

1. The for loops is REALLY off in my eyes. From my knowledge (correct me if im wrong), its suppose to be for(r=0;r<5;r++) not <=. BUT somehow im getting the results I want (in terms of formatting). HERE IS MY OUTPUT

Quote
300 450 500 510
510 600 750 627
627 100 420 530
530 621 730 200
200 50 58 100
100 83 4 5
Press Enter to return to Quincy...

View 8 Replies View Related







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