C++ :: Read N Data Items Into Two Arrays (X And Y) Of Size 20

Apr 1, 2013

Trying to do a homework assignment for a class and how to read a file into an array. I've looked in our book and on several other forums and cant seem to find any examples of this. Below is the assignment I'm working on. I have a shell of the program that I can get to run, but getting a .txt file to read into an array is something I cant seem to figure out how to do.

Write a program to read N data items into two arrays, X and Y, of size 20. Store the product of the corresponding pairs of elements of X and Y in a third array Z, also of size 20. Print a three column table that displays the arrays X, Y, and Z. Then compute and print the square root of the sum of the items in array Z. Compute and print the average of the values in array Z and print all values above the average of array Z. Determine the smallest value in each array using only one function.

Use the two data files named DATAX.TXT and DATAY.TXT.

You must use functions for the reading of the data, computing the average, printing the three column table and printing the values above average.

View 3 Replies


ADVERTISEMENT

C# :: How To Size ListBox Height To Items

Jul 24, 2014

Is there a way to set the height of a listBox to show all of the items without having to kick in the vert scrollbars? I've searched on this question but can't find how to do this.

I want to kind of auto-size my listBox height to accommodate my items (within reason and perhaps set a max height which would kick in the vert scroll bars.

View 9 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++ :: 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 :: Splitting TXT File Items Into 2 Different Arrays

Oct 21, 2014

im new to programming and new to C, just started with arrays and im somewhat stucked, where i have a .txt file which contains items and prices. I want the items and the prices split into 2 different arrays

The .txt looks like that:

orange 0.89
banana 0.79
apple 0.59

I now want to split the items in a char items[100][100] and float prices[100]. how to split this, preferably with fscanf ?

View 7 Replies View Related

C++ :: How To Properly Concatenate Two Items That Contain Binary Data

Mar 30, 2015

I have two std::string data items that contain binary data (so it may have the null character!). What is the proper way to concatenate them to preserve all of the data? I am guess a simple:

string string3 = string1 + string2;

Will not work, as it will terminate string3 on the first NULL character it encounters.

View 3 Replies View Related

C++ :: Arrays Are Actually Created With A Size Indication?

Jan 14, 2014

Reading Effective C++ by Scott Meyers, and Item 16 claims that when an array is created, the compiler reserves a block of memory at the very beginning to indicate how many objects are in the array.

n = number of objects
|n|index0|index1|...etc

Scott Meyers wrote:This is just an example, of course. Compilers aren't required to implement things this way, though many do.

Supposedly, this how delete knows how many objects to destruct. And if you were to do something like:

int* foo = new int;
//Stuff
delete[] foo;

Then delete would interpret the first block as the number of items to destruct, then continue on and destruct that many blocks of memory onward, causing UD behavior.

Is there any truth to this?

View 1 Replies View Related

C++ :: Using Arrays As Sources Of Data For Arrays In A Structure?

Feb 6, 2014

I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.

I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.

How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)

Code:

int _tmain(int argc, _TCHAR* argv[]) {
int comm = 10;
int targ = 5;
int death;
struct AI_WORDS

[Code]....

View 2 Replies View Related

C :: Make Array Which Contains Arrays But With A Variable Size

Jan 29, 2015

I am wondering how I could make an array which contains arrays, but with a variable size.My first try..

Code:

int array[][] = {{1}, {2}};

But this isn't proper

View 2 Replies View Related

C/C++ :: Functions Passing Size Of Arrays As Value Parameters?

Mar 11, 2014

we were given this code:

// Music Shuffle Program
// This program takes an array of strings and randomly permutes their order.
// This allows us to generate new song shuffles.
#include <iostream>

[Code]....

or are they referring to something else?

View 4 Replies View Related

C++ :: Limit Size Of String (arrays And C-style Strings)

Dec 9, 2014

how do I tell the if statement to output this error message 'exceeded the maximum amount of characters' that has its characters stored in an array using c-style string?

[INPUT] The cat caught the mouse!
[OUTPUT] Exceeded the maximum amount of characters (max 10)
#include<iostream>
#include<string>

[Code]....

View 2 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C/C++ :: Read Contents From A File And Use As Size Of 2D Array - Error C2087 And C2133

Oct 20, 2014

Goal:
Read contents from a file and use as the size of a 2d array.

Problem:
C2087: Line 27 : "a1" : missing subscript
C2133: Line 27 : "a1" : unknown size

Code :
int rows;
int columns;
ifstream fObject("inputdata.dat");
fObject>>rows;
fObject>>columns;
char a1[rows][columns];

I am not sure why this is occurring, or if there is a better way to do it.

View 3 Replies View Related

C :: Size Of The Data Type

Mar 4, 2014

I want to find the size of the data type with out using sizeof() operator.

View 9 Replies View Related

C++ :: Loop To Read In Data And Check Data

Oct 8, 2013

struct receivers
{string fname, lname, team,;
int receptions, yards, TDs, longest,rec20, fumbles, yac, firstdown;
double, averagepergain, averageperrec
}

View 2 Replies View Related

C++ :: Size Of Object If There Is No Data Member In Class

Aug 20, 2013

What is the size of object in c++ , if there is no data member in the class ?

View 3 Replies View Related

C++ :: Data Type Size - Performance With References

Aug 16, 2012

Here's what I'm trying to do : A simple readout that shows the input/feedback values for 10 different sensors (i.e. a motor, a thermocouple, light sensor, etc).

What I got so far:

The data is stored in 2 different arrays:

One array is a 2D string array that stores descriptions, and won't be changed:

Sensor ID, Sensor Type, Input Signal, Feedback Signal
["A"]["Motor"]["PWM Signal"]["RPM"]
["B"]["Thermocouple"]["N/A"]["TempC"]
etc

The second array is another 2D int array that stores all the data values:

Input Signal, Feedback Signal
[0][0] // for Sensor A, Input is 0 PWM, 0 RPM read from sensor
[0][25] // for Sensor B, Input is 0, 25C read from sensor
etc

My question: I'd like to re-write the code to incorporate the new things I learned in c++. Right now, the descriptions for all 10 sensors are in 1 array and the sensor values are in another array. If I use pointers to access the values, is there a performance difference between:

1. Keeping it as is, with 2 2d arrays
2. 1 big structure that has descriptions and sensor values for all 10 sensors (i.e. combining everything into 1)
3. 1 parent class, and 10 different objects for each sensor (i.e. splitting into 10)

View 2 Replies View Related

C :: How To Read A File Into Parallel Arrays

Nov 3, 2014

I have trouble reading data from a text file to parallel arrays. the text file (album.txt) has this format:

Code:

(song1 title)
(song1 artist)
(time1)
(song2 title)
(song2 artist)
(time2)
.
.
etc

I want to store these data into three arrays:

title [], artist[], time[] this is what I have so far:

Code:

#include <stdio.h>
#include <string.h>
#define SIZE 9999
int main ()
{

FILE *tFile;
char title[SIZE];

[Code]...

the problem is that each array reads the whole text? I want to store artists name in char artist[] .. titles in char title[] and so on

View 5 Replies View Related

C# :: Read And Write 2D Arrays Into Fields?

Nov 17, 2014

reading and writing 2D arrays I've been trying out a few tutorials using FileStream but I couldn't get any of them to work.

Anyway what I'm trying to do is save the playerArray to a .txt file and then read from that .txt into the fields within the GUI. This is supposed to act as a database.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 2 Replies View Related

C :: Read Text From A File Into Arrays To Set Categories

May 15, 2013

I'm making a Jeopardy game and when I read text from a file into arrays to set the categories, questions and answers a couple of the strings are not terminating and they are printing that junk box thing at the end.

When I use the debugger and print the problem strings they are showing up as "Thanksgiving21" or "Calvin Klein21" but all the other strings aren't having that problem.

Then for example I will change "line[strlen(line)-1] = '';" to "line[strlen(line)] = '';" and other strings will have that problem but not those stated ones. I'm using line[strlen(line) - 1] = '' to get rid of the newline fgets appends on the end of the strings.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
FILE *file = fopen("questions", "r");
char *string[66], line[150];
int idx;

[Code]...

View 6 Replies View Related

C++ :: How To Read External File Into Parallel Arrays

Dec 8, 2013

I have an external file that I would like to read from this file and place the values into parallel arrays. The file has these values:

Rams
Titans
23
Patriots
Rams
20
Steelers
Seahawks
21

View 1 Replies View Related

C/C++ :: Program That Can Read And Edit Structure Arrays

Feb 5, 2015

writing this program where you can search a structure array for existing elements, add new elements to the structure array, and find and display entire elements of the array structure and all.

Right now I am stuck on adding new elements to the structure array.

#include <iostream>
#include <string>
#include <iomanip>

[Code]....

Any methods to displaying the a array structure or editing it ....

View 6 Replies View Related

C++ :: Initialize String Data Members As Nullptr Or As Zero-size Array?

Nov 4, 2014

Is it generally better to initialize string data members as nullptr or as a zero-size array?

I can understand the former is superior from a memory-use perspective and also not requiring the extra allocation step. However, many string management functions will throw an exception - wcslen for instance - if you pass them a null pointer. Therefore I am finding any performance gained is somewhat wiped out by the extra if(pstString==nullptr) guards I have to use where it is possible a wchar_* may still be at null when the function is called.

View 4 Replies View Related

C++ :: Data Structures - File Size Not Decreasing When Erase A Record

Nov 26, 2014

// my size is not decreasing when I erase a record.
//dvr_hwch.cpp

#include <iostream>
#include <iomanip>
#include <cassert>
using namespace std;
#include "hash_chn.h"
void print_menu( );

[Code] .....

View 1 Replies View Related

C# :: Convert Dictionaries To Arrays To Read And Write Sequentially

Nov 27, 2011

Code:

// declare child arrays
public string[,] childcolor;
public string[,] childgeneo;
// create dictionaries
public Dictionary<string, int> colors = new Dictionary<string, int>();
public string color; // name for dictionary
public Dictionary<string, string> geneo = new Dictionary<string, string>();

[Code]...

I'm getting "field' is used like a 'type' error on jw.childcolor which causes other parts to error out.

How do I fix this & why am I getting the error?

I want to convert the dictionaries to arrays to read & write sequentially.

View 4 Replies View Related

C :: Read Specific Values From A File And Store Them In Arrays

Apr 14, 2013

What i try to do is to write a code which reads some specific values from a file and stores them in an array. My File looks like this

Code:

XFOIL Version 6.96
Calculated polar for: Myfoil
1 1 Reynolds number fixed Mach number fixed
xtrf = 1.000 (top) 1.000 (bottom)
Mach = 0.000 Re = 0.200 e 6 Ncrit = 4.000
}

[code]...

View 11 Replies View Related







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