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?
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.
I am working on a wage application with four options which are as follows:
Subtracts an amount from the shop bank account (The account is text file "shop"). You do not need to add the same amount to another account but you should record the transaction with a timestamp in a separate file. The application should prevent the account balance from becoming overdrawn.
List the five most recent transactions to the screen. If there haven’t yet been five transactions then list all of them.
Print the account name, number and current balance to the screen.
Exit the program.
I have completed 1,3 and 4 but I am completely stumped as to how to go about number 2.
I have a partially filled array and I want to put that into a text file. Say I don't know how partially filled it is. How would I stop at the very end of the array where it has the last amount of data.
ex. int array[9] = {1,2,5,6}; ofstream output("txt file"); for(int i = 0;i < 9; i++){ output << array[i] }
How would I stop as soon as i becomes 4 because that is when the array stops?
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);
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:
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;
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.
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 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.
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
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.
I have a class that uses std::vector. I push back class objects onto the vector but when I try to cout the data members (with get functions) I get garbage values.
Here is the class:
#ifndef JOBS_H #define JOBS_H #include <iostream> #include <iomanip> #include <vector> #include <string> using namespace std; class Jobs{
[Code] ....
I know I am missing the implementation of several functions but I'm just testing my vector to see if it is working and it isn't. The getBlockValue() function should output 0 for each job. When I push back one object the output is 0. When I push back 2 objects the output is 0. However when I push back 3 objects I get random values. Why is this? I thought vectors were dynamic?
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"
I have got an assignment. It is about comparing two files one file has sentences and the other abbreviations. so far i have managed to compare the abbreviations which appear in the sentence and erase punctuation linked to abbreviations.
However I am currently stuck on putting the punctuation back in when outputting the file. I am also stuck with replacing matching words in the sentences with the expanded abbreviations. Not sure which code to show. but sentences and abbreviations are below.
ABBREVIATIONS
Aberd Aberdeen admin administration approx approximate Austral Australia div division Capt Captain Comdr Commander e east HQ Head Quarters m metres mil million mt Mount n north NATO North Atlantic Treaty Organisation NSW New South Wales pop population s south sq square w west
Text file
NATO troops were on exercise in Aberd Capt Jones of the first div told Comdr Frank that his troops were near the E flank of the NATO forces. Complaining about the amount of Admin, Capt Jones radioed the NATO HQ asked for navigation relative to the HQ. The Captain then left.
For example the abbreviation "Aberd" in the sentence above needs to be replaced with Aberdeen from the abbreviations file. I need the last part of the abbreviation not "Aberd Aberdeen" need just "Aberdeen". Hope the info is understandable.
Code: ig_cfunc.cpp:1609: error: `calc_rel_branch_degree' undeclared (first use this function)
I have deleted all of the objects and recompiled to make sure that everything is in sync. I can't see what the issue is here and I'm not sure what to do next. This code actually worked until I changed the name of the function, so the types are all correct and such. This is the format I use for all external functions ....
Why I am getting an error (-1) when trying to write to a file. Here is the function - I did not include the rest of the code - not sure if I am leaving anything else out - I assumed it was a write permission issue?
Code: #defineDATAFILE "/var/chance.data" //File to store userdata voidregister_new_player() { int fd; printf("-=-={New Player Registration } =-=- "); printf("Enteryour name: "); input_name();
[Code] .....
Result
Code: user@ubuntu:~/examples$./game_of_chance -=-={New Player Registration } =-=- Enteryour name: test [!!]Fatal Error in register_new_player() while opening file:Success user@ubuntu:~/examples$