C++ :: Outputting Associated Data In Struct

May 2, 2013

So this is the last part of a program I've been working on for four weeks now. This question may be a tough one considering the amount of files included in the program.

The program is to read in a file of requests between two cities, read in a file of flights and cities that occur between the cities. It then checks to see if there is a path between the flights and output an itinerary. I have the correct itinerary outputting, but when attempting to output the associated flight number and price according to the city, I am getting odd data. How can I output the correct flight number and price associated with each flight on the itinerary.

I'll post out the output I am currently getting and the section where I am outputting the data. I'm sure I'll need to post more files so the program can be understood.

Don't want the code done for me, just a point in the right direction! I don't want to let this program defeat me!

Output: Code: Request is to fly from Atlanta to San-Diego.The flight itinerary is:
Flight # From To Cost
10 Atlanta Chicago $134529069
10 Chicago Miami $134529069
10 Miami Dallas $134529069
10 Dallas San-Francisco $134529069
10 San-Francisco San-Diego $134529069
This function finds a path between cities. Code: bool flightMap::IsPath(string originCity, string destinationCity){
StackClass aStack, bStack;
flightStruct flightRec;
string topCity, nextCity;
bool success;
int index = 0;

[Code].....

View 1 Replies


ADVERTISEMENT

C++ :: Getting Data From A File And Outputting

Apr 17, 2013

I am given a data file that contains sports data for 24 people. There are two rounds of the event. The first 48 lines of the file give the data for the 1st round and the second 48 lines give data for the 2nd round. The file looks like this:

Azrin, 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
Burks, Arthur
2.8 4.5 5.4 6.6 7.7 8.8 5.6 6.5
Crick, Francis
1.6 6.5 6.5 6.5 7.3 7.5 7.8 5.6
and so on ............

This data continues for all 24 people and then repeats with different score values for the second round. The first number after the persons name is the level of difficulty and then next 7 numbers are the scores. I am trying to get this data out of the file and set it up in the following format:

Name Of Person
Round 1: level of difficulty scores
Round 2: level of difficulty scores

So the table for the above data would look something like this:
Arzin, Neil
Round 1: 2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6
Round 2: 2.1 6.0 5.0 6.5 7.8 5.6 8.8 7.6
Babbage, Charles
Round 1: 2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5
Round 2: 2.3 5.4 6.5 7.6 8.7 7.2 5.4 5.5

And so on for all 24 people. This is the code I have for it, but it just reads the file directly:

// I have already opened the file!
while (inFile) {
string name;
getline(inFile,name);
cout << name << endl;
}

How I can do some sort of formatting on this data?

View 1 Replies View Related

C++ :: How To Stop Outputting Data Based On A User Input

Sep 27, 2013

how to stop outputting data based on a user input. The text file is as follows:

1. a
2. b
3. c

and the code I'm using is as follows:

int main (){
string line;
int search;
cout << "Enter a number from 1-3" << endl;
cin >> search;
search++;
ifstream myfile ("example.txt");

[Code]...

What I want to do is to just output number 1 (the whole line) if the user enters number 1. However, I get an error on the second condition w/c is the "&& line!= search"

View 1 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 :: Initialize Data Member In Struct

Mar 28, 2013

I was looking at some linked list material and was wondering something. Can you initialize a data member inside a struct like in C++? i.e.

Code:
typedef struct node
{
int data;
struct node * next = NULL; // this is the line in question
} LLnode;

View 3 Replies View Related

C++ ::  Accessing Struct Data In A Queue

Mar 24, 2013

I have a queue of structs. I would like to access one of the two pieces of data at the front of the queue that each struct maintains.

Here is some of my code:

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <queue>
using namespace std;

[Code] ....

What I am asking is how do I get the priority of the struct item at the front (lane1.front()), in this case?

View 8 Replies View Related

C++ :: How To Check If Data In Struct Has Changed

Nov 21, 2013

I am working on this project where I need to see if data in a struct has changed and if so I need to do something. With that being said, is there a way to check to see if data in a struct has changed. My first approach was to make a copy of the struct and compare the original struct with the copy but I was having problems with the operator==.

View 2 Replies View Related

C :: Binary Search Tree - Struct Data

Oct 24, 2013

I was working with binary search tree and came up with the solution:

Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct data {
int x;
struct data *left;
struct data *right;

[Code] .....

View 6 Replies View Related

C :: Working With Files / Struct And Manipulating Data

Dec 17, 2013

I have the following code and I am trying to do simple math calculations to the data. I need to take the car price (y) minus down payment (z) and then divide that quantity by 12 times "yearsx" That answer is then assigned to x. The problem is that x will not print the correctly!I also noticed that if I increase the "count" to amnything higher than the number on lines in the file, I get the correct value for x but only on the last set of the struct..my file reads as follows:

last_name first_name car_price down_payment years
johnson bill 10,000 2,000 3

When I printf the struct to the screen, i need to do the following:

x = (10,000 - 2,000)/(12*years);

but this is the math part that wont work. I have checked and doubled checked number types and I cant get it right.

Code:

#include<stdio.h>
#include<stdlib.h>
#define FILENAME "file.txt"
#define SIZE 100
}

[code]....

View 3 Replies View Related

C++ :: Initializing Const Struct When Data Is A String Literal

Feb 23, 2015

I have a struct like this:

Code:
struct String{
char* data;
std::size_t size;
};

I would like to be able to create const variables of this type for string literals.

Code:
const String message;

Is there an elegant way to create a const String like this when data is a string literal?

I tried this:

Code:
const char *string_data = "Hello";
size_t string_size = strlen(string_data) + 1;
const String string = {string_data, string_size};

The problem with that is that string.data isn't considered const during the initialization of the String struct so the compiler throws an error. It doesn't feel very elegant to do it like this either way.

Is there an elegant solution to this problem? I would like to avoid making a copy of the string literal.

View 7 Replies View Related

C++ :: Multi Data Types In A Line And Read To Struct?

Aug 14, 2014

How can I read this file in to my struct?

12345Joe Lim KH879.00
12233Kay Suet Yee35.98
23781Leong Jing Yang 10.00
67543Woon Tian Yi500.50
struct master {
unsigned short int IDnum;

[code]....

not working

View 16 Replies View Related

C++ :: Struct As Variable - Zero (init) Data In Class Constructor

Feb 8, 2013

at my work we use a static analysis tool and it is pointing out some uninitialized variables. One of which is a class member variable which is a C struct. Now, that variable is already declared in the header file for the class.

Currently in the class constructor I am doing:

Code:
memset( &thestruct, 0, sizeof( thestruct ) );

Is there a C++ way to do this? I Googled this but all I really found was:

Code:
StructDef thestruct = {};

Which doesn't really apply here.

View 7 Replies View Related

C :: Parsing Binary Data File By Casting A Buffer - Accessing Double From Struct

Jan 4, 2014

I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.

Code:

typedef struct InvoiceRow {
uint INVOICE_NUMBER;
...
double GROSS;
...
char VAT_NUMBER[31];
} InvoiceRow;

If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...

Code:

typedef struct example {
double d;
}

example;
example *blah = (example*)row->GROSS;
printf("%f", blah->d);

View 7 Replies View Related

C++ :: String Outputting Twice?

Nov 3, 2014

When I run the program, the prompt I am giving the user before I collect their data, shows up twice in row. Here's the part of the code I'm referring to:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
// method prototypes
void characterInstructions();
void phraseInstructions(); //

[Code] ....

View 6 Replies View Related

C++ :: How To Pause After Outputting Results

Feb 19, 2013

I mean on the executable file. It just displays the results and quickly flashes away, cin.get() has no effect and system("PAUSE") is undeclared.

I never found a single sure way to pause effectively. Is there a method that works all the time? Sometimes cin.get() gets skipped even in the code itself. The IDE I am using is Code Blocks if that matters any.

View 4 Replies View Related

C++ ::  NCurses Outputting Vectors

May 19, 2013

The following code works perfectly with "normal" C++

#include <iostream>
#include <vector>
int main() {
std::vector <std::string> hello {

[Code] ....

This prints "HELLO" on the screen. A function a bit more like NCurses is:

for (std::vector <std::string>::const_iterator it = hello.begin(); it != hello.end(); it++) {
std::string temp = *it;
std::cout << temp.c_str() << std::endl;
}

This still works with "normal" C++. Now, how do I get this working with NCurses? I tried

#include <curses.h>
#include <string>
#include <vector>
int main() {
initscr();

[Code] ....

But this just gives me an empty screen.

View 2 Replies View Related

C++ :: Outputting Randomized Arrays

Apr 7, 2013

For an assignment I am having a user enter the name of a file that contains "Song Data" the file is set up like this:

(example)

1012 C
3333 R
90 E

And so forth for 15 lines. The first value represents the song Id and the second is a character C, D, E, or R that represents the type of song. After the file is opened I have two parallel arrays that are read from the file:

1. int songId[15]
2. char typeOfSong[15]

I am able to read the entire file, which symbolizes playing the playlist in order, but now I have to play a randomized playlist.

It has been given to us that we need to set up two parallel arrays, that are also parallel to the first two (songId and typeOfSong). These must also be one dimensional. The first array will will be indexes into the songId array telling is what order to put the songs in and the second is an array of true/false values telling us if the song has already been chosen or not.

I have that:

void playRandomPlaylist (int songId[], char typeOfSong[]) {

// the size of the file and therefore arrays is known
rand() % songId[15]

// choosen and notChoosen symbolizing true and false values
typedef enum {choosen, notChoosen};
}

View 1 Replies View Related

C++ :: Comparing Value To Array And Outputting

Feb 6, 2013

i have 3 arrays total, 2 of them i am comparing to see if any of the values match at all, and then i am putting the value that matches into the 3rd array. currently i am trying

int isthere (int match[], int maxmatchLength,
const int vec1[], int vec1Length,
const int vec2[], int vec2Length)
{
for (i=0; i<vec1Length; i++)
if vec1[i]==vec2[i];
vec1[i] = match[i];
}

But this will just match the same values are in the same spot. how do i fix it so that it compares one value in the first array to the whole second array, before going to the next number.

View 1 Replies View Related

C/C++ :: Getting Error When Outputting To File

Sep 5, 2014

it isn't actually writing anything to the file. It is opening the employeesOut.txt file but not writing anything. I'm getting the error

libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: stoi: no conversion
(lldb)

I believe the error is within my main.cpp, so here that is, I have multiple classes.

#include <iostream>
#include <string>
#include <fstream>
#include "Employee.h"
using namespace std;
bool openFileForReading(ifstream& fin, const string& filename);

[code]....

View 12 Replies View Related

C/C++ :: Sizeof (struct) Returns 6 More Bytes Than Actual Struct Size?

Sep 14, 2014

#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;

[Code] .....

I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.

View 9 Replies View Related

C++ :: Overloading Using IStream - Not Outputting Objects

Mar 6, 2015

I'm implementing istream and ostream overloading for a program that takes in 3 objects, adds them, subtracts them, and multiplies them. I'm having difficulty in outputting the objects. The program outputs the first object just fine, but for some reason defaults the other two...

Code:

#ifndef COMPLEX_H
#define COMPLEX_H
#include <string>
Class Complex

[Code] ....

View 1 Replies View Related

C++ :: Sudden Exit Right After Outputting Expression

May 1, 2014

This program I'm working on just exits unexpectedly right after outputting "Expression?"

int main(void) {
provideHelpIfNecessary();
while(true){
cout << "Expression? ";

[Code] ....

And I'm not allowed to change anything in main().

View 2 Replies View Related

C++ :: Zlib Outputting Blank File?

Oct 30, 2014

I wrote a program to compress a file with gzip, which works fine. I also wrote a program to decompress the gzip file, which runs but outputs a blank file.

Code:

main.cpp:
#include "decompress.h"
int main(int argc, const char * argv[]) {
if(argc == 3) {
decompressor(argv[1], argv[2]);

[code].....

View 4 Replies View Related

C++ :: Outputting First Word Of Each Sentence In String

Dec 20, 2014

I have been trying to get this to work for a while now - with no success.

Basically I am trying to write a function which the returns the first word of each input sentence in a single string - this is part of a larger cryptography program I am working on.

So for example, if this string was passed into the function:

"This is what I mean. Is it right? A poor puppy abandoned. Secret torturing of dogs are happening. Message: be on the watch."

It should return:

//declared in class "steganalyse"
string cyphertext;
string punctuation = ".?!;:'";
book is_first_word

[Code] .....

But this only returns the first word:

This

Any other way to return the first word of each sentence in a string.

View 1 Replies View Related

C++ ::  Program To Grade T Or F Test Not Outputting Information

Jul 2, 2014

I wrote a program to grade T or F test. It is running, but not outputting the information.

Code:

#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
double grading(char*answer, char* stuResponse, double graded);

[Code] ...

text doc:

TFFTFFTTTTFFTFTFTFTT
ABC5403 TFTFTFTT TFTFTFFTTFT
ABC5404 TFTFFTTFFTFFFTTTFTFT

View 5 Replies View Related

C++ :: Outputting Contents Of Stack On Input Line?

Sep 3, 2013

outputting the contents of my stack on the input line.

View 7 Replies View Related







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