C++ :: Output Data From Two Sorted Arrays Into One File?

Apr 7, 2013

I am trying to output data from two sorted arrays into one file(which should also be sorted). The program works for most of the data, but after it reaches a certain record begins outputting garbage. I'm sure part of the problem is that I don't know what to include in my while loop that outputs to the file.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

View 4 Replies


ADVERTISEMENT

C :: Function That Merge Content Of Two Sorted Arrays Of Double Type Values

Nov 4, 2013

I need to write a function that will merge the content of two sorted arrays of type double values. The function should not assume that both its input parameter arrays are the same length.

Here is my program so far - I know there is alot of errors and mistakes:

Code:

#include<stdio.h>
void merge(int firstArray[],int secondArray[],int size) {
int mergedArray[size],i=0,j=0,k=0;
while(i<size||j<size) {
if(i==size) {

[Code]...

View 2 Replies View Related

C++ :: Pointers And Arrays - Program To Display Sorted List And Average Of Scores With Appropriate Headings

Apr 22, 2014

I am writing a class that dynamically allocates an array that holds a user-defined number of test scores (test scores go from 0 to 10 both included). Once all the test scores are entered and validated (values only between 0 and 10, both included), the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates theaverage of all the scores.The main program should display the sorted list of scores and the average of the scores with appropriate headings.

View 6 Replies View Related

C++ :: Multiple Of CSV File Used As Input / Extracting Data To A Output File - Getline Function

Jun 4, 2013

I have written a C++ program I have multiple of CSV file used as input, which I open one at a time and close it after extracting data to a output file which is the only file.

I run getline(inFile,line);
outFile << line << endl;

I run this code, and only part of it is goes to the output file I got, also have spacing randomly to specific file and inconsistent

But when I slower the code, like system("Pause") in the loop, I can get extract what I want perfectly....

Is my program running to fast, why getline would be skipping part of what things I want?

View 11 Replies View Related

C++ :: Output From Data File Not Working?

Feb 27, 2014

i need my code to stop outputting all the numbers throughout the steps it is going through i just need it to output the total

this is my input
M
C
C
C
L
I
V

and its output is

Your total is 1000
Your total is 1100
Your total is 1200
Your total is 1300
your total is 1350
Your total is 1351

i just need it to output the last number

// write a program to read a string of characters
// that represent a Roman numberal and then convert
// to Arabic form ( an integer
// input from data file

[Code].....

View 1 Replies View Related

C++ :: Data File Output To Screen

Oct 13, 2013

I am having trouble outputting the file "output1.dat" to the screen. here is my code -

#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
//Outputs a description of what this program does
void intro();
void sort_merge(ifstream& in_1, ifstream& in_2, ofstream& out_1 );

[Code] .....

View 2 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++ :: 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 From A Txt File And Then Write A New Text File With Sorted Line

Jun 11, 2014

I have a .txt file which I want to read from and then write a new text file, this time with sorted lines. It is easy to sort one value, but what about sorting entire lines based on one value?

I want to sort the lines based on the FIRST value.

Example text file contents:

values;data
5.01 100
2.9 342
2.69 43534
10.1 43
6.8 45324

Output: Text file containing

2.69 43534
2.9 342
5.01 100
6.8 45324
10.1 43

It's easy to do this if there was only 1 number on each line, but I do I sort all the lines based on the first number in each line?

View 2 Replies View Related

C++ :: Taking Data From Files And Output Information To Another File

Apr 2, 2014

Whenever I run my program, It should be taking this string of information:

Shampoo 10 8.75 87.50
Pen 3 2.50 7.50
Headphones 5 20.99 104.95
MacAir 1 879.23 879.23

Raspberries 6 4.99 29.94
Oranges 5 2.79 13.95
Apples 3 3.85 11.55

From one file and outputting it to another, the finished product should look like:

Shampoo 10 8.75 87.50
Pen 3 2.50 7.50
Headphones 5 20.99 104.95
MacAir 1 879.23 879.23

cheapest item = Pen
most expensive item = MacAir
total cost = 1079.18
shopper = Mary Kay

Raspberries 6 4.99 29.94
Oranges 5 2.79 13.95
Apples 3 3.85 11.55

cheapest item = Oranges
most expensive item = Raspberries
total cost = 55.44
shopper = Winnie B. The Pooh

When I run my code however, it doesn't get past shampoo and will continue to add shampoo to the total cost infinitely. How can I change the code to produce the proper information?

CODE:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <float.h>
#include <sstream>
#include <string>
using namespace std;
ifstream input_file;
ofstream output_file;

[Code] ....

View 1 Replies View Related

C :: File Containing Sorted Numbers

Mar 6, 2015

suppose you we given a file containing sorted numbers

ie
1
2
4
6
7
9
10
12
14

and you needed to inset the number 11 into the file and keep it sorted.

View 8 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++ :: Struct - Getting Grades Of The File Sorted

Jul 21, 2014

My code has no errors. I'm just having problems with getting the grades of the file sorted. grades is not a struct, but is a int inside struct School. Below is what I;m having problems with(this is just the code I started working with,I made a few changes but it didn't work,I have no clue)

void selectionSortG() {
Students min;
int key;
for (int i = 0; i < size; i++){
min = student[i];
key = i;
for (int k = i; k < size; k++)

[Code] ....

View 2 Replies View Related

C :: List Of Words That Need To Be Read In From A File And Then Sorted

Apr 4, 2013

I'm given a list of words that need to be read in from a file and then sorted. I was given a certain way to do it .

Code:
#include <stdio.h>
#define MAX 100
void print_ar(char x[][MAX], int size);
int strcomp(char x[], char y[]);
int strlength(char x[]);
void selection_sort(char c[][MAX], int size);
void strcopy(char x[], char y[]);

[Code] ...

Here are some words from the list

school
aibohphobia
lists
alula
bake
cammac
civic

I cannot figure out what is wrong at the moment. .

View 3 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++ :: Outputting Data From File Into Structs And Arrays Of Structs

Apr 15, 2013

I am having a lot of trouble being able to get data from a file and input it into given structs and arrays of structs and then outputting the file. We are given a file that contains 96 lines and looks like this:

Arzin, Neil
2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6
Babbage, Charles
2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5

This file continues for 24 different people and then repeats with different scores (the second line).
The first number, in this case is 2.3 for both people is a difficulty rating. The next 6 numbers are scores.

We are given this data in order to set up our structs and arrays and my code:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main () {
ifstream inFile;
inFile.open("C://diveData.txt);

[Code] .....

View 1 Replies View Related

C++ :: Arrays Of CStrings - Garbage Output?

Mar 20, 2013

Here's my code:

struct Member {
char *name;
char *address;
char Interests[][10];//<------problem
int numofInterests;
Numbers digits;

[Code] ....

Now the Program:

newMember.Interests[numofInterests];
newMember.numofInterests = numofInterests;
for(int i = 0; i < numofInterests; i++) {
printf("Enter %s's %i interest: ", newMember.name, (i+1));

[Code] ....

it's a array of cstrings, but i can't figure out how keep it from outputting garbage, i'm assuming it's because i didn't end it with a null terminator but when i did, it didn't work.

View 1 Replies View Related

C/C++ :: Tic Tac Toe - Initialize Arrays At Zero And Output Board To Screen

Sep 13, 2014

/* This is what I have so far what i am trying to do is to initialize the arrays at zero and output the board to the screen. Part of the problem is the user has the option of the board size. All this is suppose to do is to output the board to the screen. I am having problems understanding 2D Arrays.
*/

using namespace std;
int main() {
const int BOARD_MAX = 10; // Maxinum Board size.
const int BOARD_MIN = 3; // Minimum Board size.
array = [COL];
array [ROW];

[Code] ....

View 5 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 :: Storing PPM Data Into Arrays

Mar 29, 2014

I am doing this program where I analyze colors in a ppm file. Now I am having a hard time storing the data into arrays in this order...

P3
600 339
255
44 5 8
44 5 8
43 4 7
42 3 6
42 3 4
44 5 6
...

So far i tried using fscanf()

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>

#define DEBUG true
#define CHECK true

[Code] ....

I then realized that the order that the second method gave me will make it very hard for me to calculate the RGBs. Because they will be calculated like wise..

P3
600 339
255
44 5 8 = sum
44 5 8 = sum
43 4 7 = sum
42 3 6 = sum

42 3 4 = sum
44 5 6 = sum
...

but that isn't the issue right now..

View 10 Replies View Related

C :: Fscanf Data To Arrays

Apr 17, 2014

I am a very fresh c programme user, in fscanf data to arrays. Somehow it just doesn't gets recorded, wonder what is wrong with my code? When I printf the array it always ends up with random numbers.

Here is my code:

#include <stdio.h>#define SIZE 2
#define count 2
int main()
{
[code]....

and the file i am trying to read from :

Code:
1, 2, 3, 4
5, 6, 7, 8
8, 9, 10, 11

I am trying to scan a list of 3 by 4 numbers and the 4 numbers of each column to the 4 different arrays, so if I read from the data above, i get an array with numbers 1,5,8; another with 2,6,9 and so on. Is it how its done in my code?

View 2 Replies View Related

C++ :: Using Arrays To Store Data?

Mar 25, 2013

start writing a program to store some information and then have it recalled. I would like to be able to store a list of the video games I own because i thought it would be fun :)

View 1 Replies View Related

C :: Passing Arrays To Other Data Has Pointers?

May 7, 2013

I am looking for an example of when passing arrays to other data that has pointers,

I understand the terms I would just like to see a small example of code that actually demonstrates this process.

View 4 Replies View Related

C/C++ :: Arrays And Enumerated Data Types

Feb 18, 2014

I am doing a programming assignment. This program asks you to collect statistics on precipitation and temperatures from the four quarters of a year and print the calculated results. It is an exercise in using enumerated types and arrays. The measurements are entered at the end of every quarter.

Major variables (there are other variables) in the program:
Variable called: month of type Summary_Month (the enumerated type)
Arrays of integers called: low_temp, high_temp, precip
Array of doubles called: avg_temp

You will ask the user to enter the precipitation, low temperature and high temperature for each quarter. As you gather this data, you will calculate the average temperature (using avg_temp) for each quarter by averaging the low and high temperature for that quarter.

After you gather the information you will calculate and output : Total Precipitation for Year, Average Quarterly Precipitation, Average Quarterly Temperature, Highest Temperature for any quarter, Lowest Temperature for any quarter.

I am not getting the right output for average precipitation and temperature and I am not sure how to determine the highest and lowest temperature.

# include <iostream>
# include <iomanip>
using namespace std;
enum Quarters { March, June, September, December};
int main() {
const int NUM_QUARTERS = 4;

[Code] ....

View 9 Replies View Related

C++ :: Call Function To Output Data?

Dec 10, 2014

I am having an issue with my Call Function to output data. The compiler doesn't like the Call function to output data.

#pragma once
namespace WindowsFormsApplication1 {
using namespace System;

[Code].....

View 1 Replies View Related

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 View Related







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