I have an input file with 6 lines of data, each formatted in the following way: X,Y,Z.
My goal is to get the file name from the user, the store each line from the input file into an object of "class sample". I need to separate each variable from the file into 3 categories for further manipulation.
My idea is to get the file name in the main program, open the file, use an object to read each line and store each encountered character (non-whitespace or symbol) into it's respective variable. Then, I can use the distance equation to determine the distance between points and keep track of what class the data is in.Am I missing a step?
I am trying to write a program for the feature reduction using the RELIEF algorithm. I want it to be as simplistic as possible as I will be utilizing it often.
I am trying to read a file use the data line by line to create into an object. The current file I have is like this and the code reading the file will be found below.
1223 Fake1 Name1 60 70 80 24 89 add1 Male 1224 Fake2 Name2 61 70 81 80 24 add2 Male 1225 Fake3 Name3 63 70 82 80 89 add3 Male 1226 Fake4 Name4 63 70 83 80 88 add4 Male
The problem I am having is that I need to put delimiters in the file so that a person can have more than one name and also the address can now hold multiple strings until the delimiter.
I would like to change my file to this;
1223 : Fake1 Name1 : 60 : 70 : 80 : 24 :89 : This will be address1 : Male 1224 : Fake2 Name2 : 61 : 70 : 81 : 80 :24 : This will be address2 : Male 1225 : Fake3 Name3 : 63 : 70 : 82 : 80 :89 : This will be address3 : Male 1226 : Fake4 Name4 : 63 : 70 : 83 : 80 :88 : This will be address4 : Male
How can I update the code below so that it can use the delimiters to create an object?
void loadFile(Person people[], int* i) { ifstream infile("people2.txt"); if ( !infile.is_open()) { // The file could not be opened cout << "Error";
I'm trying to make a menu object in SFML. So far all I've added is the ability to add buttons with text inside of them. I store the buttons in a vector and then loop through that vector to draw the buttons.
The error stems from line 24 of the 2nd piece of code.
Here's what I've got:
//MenuTest.h #include <SFML/Graphics.hpp> #include <string> #include <vector> class Menu1 { class Button1 { sf::RectangleShape body;
[Code] ....
This causes an error at the line window.draw(text); in Menu::Button::drawButton(). With the error "Access violation reading location (some memory address)".
Everything up to trying to draw the text works fine.
Program background: Ticket Sales Details You will sell tickets in advance and at the door. Prices for buying in advance and at the door will be given. Also, the total number of tickets sold in advance will be given. Each guest will have a unique number. If there are n tickets sold in advance, then these guests will be numbered 0 through n-1. As the event starts, requests to buy tickets at the door may be made and these guests will be numbered sequentially, starting at the lowest unassigned number. The maximum number of guests will be 1000. The first line of the file contains the following three values, separated by spaces: Cost of the presales tickets (in dollars), Cost of the tickets at the door (in dollars), and the number of presale tickets. The first two values will be positive real numbers to two decimal places and the last will be a positive integer.
The second line of the file will contain one positive integer representing the number of auction items followed by a positive real value to two decimal places (at most) representing the minimum bid increment, in dollars. The first value is guaranteed to be 1000 or less and the second will be in between 1 and 50, inclusive.
The third line of the file will contain all the prices of the auction items, in dollars, separated by spaces, in order. Thus, the first price is the price of item 0, the next price is the price of item 1, and so on. These values will be real numbers represented to up to 2 decimal places.
The fourth line of the file will contain the three following positive integers pertaining to the raffle: the number of raffle tickets available, the cost of a raffle ticket in dollars, and the number of raffle prizes. (It's strange to have raffle tickets that don't cost a whole number of dollars.)
The fifth line of the file will contain each of the values of the raffle items, in dollars, separated by spaces, in order. Thus, the first price is the price if item 0, the next price is the price of item 1, and so on. These values will be real numbers with upto 2 decimal places.
The sixth line of the file will contain ten positive integers representing the number of each of the drinks 0 through 9, in order, that are in stock.
The seventh line of the file will contain ten positive real numbers with upto 2 decimal places representing the price of each of the drinks 0 through 9, in order.
The eighth line of the file will contain a single positive integer, numEvents, representing the number of events that occur at the charity ball. These events are split into two groups: actions by guests at the ball and awards given (raffle, auction, person, totalrevenue). All of the actions precede all of the awards. You will produce exactly one line of output for each event described. Here are the formats of each event that could occur:
If a patron buys a ticket at the door, a command will be on a line by itself:
BUY TICKET k
where k is a positive integer indicating the number of tickets bought at the door. These guests will be numbered as previously mentioned. You are guaranteed that the total number of tickets bought, including presales, will not exceed 1000. This is what I have so far and I cannot figure out why it wont calculate the total revenue. I am not completely sure if it is even accessing the if statement in main.
Code:
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1000
Interface class Person{ private: char name[80]; short age; public: void get_data();
[Code] .....
This is a simple example from and old Lafore C++ book, with a few tweaks by me. The point is simple. Save object person to a *.dat file, exit the program, then start up program again, open up *.dat file, and load contents.
The first problem is the compiler is printing a bunch of Asian characters to the file (is this normal?)
The second problem is, it's not loading the object as it should, giving me a bunch of gibberish.
someone told me to download the latest source and build that so i did, by unzipping it, cding to the source, running ./bootstrap.sh, ./b2, and finally ./b2 install. when i compile i get no errors but when i run it i get ./jade: error while loading shared libraries: libboost_regex.so.1.55.0: cannot open shared object file: No such file or directory
I need to use an instance of an object in a header file. The object requires a lot of pre-computation to be created.
I want to assign it to a "static const *NAMEobject*" field in the .h file, once it has been created. I assume that it is better to create it in another file and somehow pass it into the .h file.
Is there a way to make this program work without entering the full path to a file?
Code: ifstream ex("podatki.txt", ios_base::in); // if I type full path than program works if(ex.is_open()) cout << "The file is open and con. with the object." << ' '; else cout << "you messed up" << ' '; int counter = 0;
I am reading a file then printing the data onto the other file. It is working, however when I check to see if each variable is being properly set after reading the file a issue arises.
Example of the file being read
Code: Vehicle PV50CAN passed camera 1 at 05:33:26. Vehicle W867BRO passed camera 1 at 05:33:29. Vehicle KQ63ARU passed camera 1 at 05:33:38. Vehicle K954ITQ passed camera 1 at 05:33:40. Vehicle V220MXB passed camera 1 at 05:33:42.
I'm struggling loading a class (and it's two derived classes) from an input file. I'm trying to create an array of class objects (and derived objects) and then load them based upon what is in the file.
Main class: Code: class Book { protected: string sTitle;
[Code].....
Basically if the getline get's a P it's supposed to create a new object using the PrintedBook derived class and then store it to an array, if the getline get's to the "A" it's supposed to create an AudioBook object.
What I'm struggling with is writing something to parse the file line by line and create the objects on the fly and then store them into the array.
I'm working on a grocery store inventory project. One part is to have a shopping cart, where customers can put in up to 20 items. Because there can be up to 20 shopping carts at one time, I want to use a vector inside the cart object to represent all the individual food items.
Here's my code,
Header:
#ifndef CART_H #define CART_H #include <vector> class Cart { public: Cart(); Cart(std::vector< int >, std::vector< int >)
My Question is when i compile this code in Linux platform Using g++ compiler My sample.o's Size is 1Kb.. But when the same code is compiled in Windows platform using VC++ Compiler , My sample.o's size is 42Kb..to reduce the size in windows... Is there any proble with '#include <string>' in Windows platform.
Let's say I am using a library containing classes called class1 and class2 but both classes take three arguments to construct them. eg. class1(int a, int b, int c). and the same for class2
The below is an example of how to lay out the structure in the header and source file if class1 and class2 don't have any arguments in their constructor. But.... I'm not sure how to go about the below to take into account the constructor arguments of class1 and class2.
will copy constructor does object initialization using another already created object? I understand that it can be applied for object initialization and not for assignment.Is it correct?
I have a method to take a Tile object and make an instances of it based on some data from the original object. Than it is suppose to manipulate the a specific instance and save the results. The first loop through it works but it changes all instance as well as the base.
public static int recurse(int count, Tile[,] b,Huristic h,int check) { if (check==1) { boardState.Add(B)/>; return check; } if (check == 0)
I have a school project in which need to create a function that takes a File Object as a Reference Parameter. Supposedly, it should allow me to read the first piece of data from others separated by a space from a file. The later be able to continue reading from the next piece of data.
I know how to set things up to read from the data file, such as using
I'm working on a cross-platform threading project, the aim is to start 1 worker-thread that has a queue of worker-items which are serviced by the thread.
The threading framework works fine, both under Windows and LINUX, albeit as designed under Windows, and in a modified form under LINUX.
I have this CSnmpTrapd class which is designed as a worker-item for the worker-thread, it listens for incoming SNMP traps and decodes the packets, this is implemented in csnmptrapd.cpp and csnmptrapd.hpp.
1) When I add this piece of code to my makefile and re-compile the app successful... the app will start (or not?) but generates no console or file logging as is expected, it will not even show printf() output which was added as first statement in main(). My app handles CTRL-C to terminate and this works !?!? But I'm actually not sure my app works at that point.
2) When I compile the app without csnmptrapd.cpp and start it, it will generate console and logging output and behave as expected.
3) When I add the CSnmpTrapd class implementation to an existing cpp file in the project, it will compile and run as expected... the worker-thread handles the CSnmpTrapd worker-item as it should, incoming SNMP traps are captured and decoded, logging generated
how to structure my classes so that they all "wire together" and inherit the proper functions and data that I want them to. I want to have a Car.c and car.h which are "wired" with body.c/body.h, which in turn is wired with a frame.c/frame.h, wheel.c/wheel.h, and driver.c/driver.h.
Each part of the car holds some type of data, mostly ints: The car has a (total) mass and car_name. The body has a mass and color. The frame has a mass. The wheel(s) have a mass and force. [There will be 4 instances of wheel] The driver has a mass and driver_name. Each of these functionalities must come from their respective .c and .h files, and be amalgamated in the car.c and car.h (which should contain all the functionality of its parts). Then, in my main test program, I am to make an instance of car and hardcode in its values of: mass (which comes from the total mass of all of its parts, this is where i start to lose it.
How will I access its parts' masses in the test program?), color (a character array), current position (an integer), current velocity (an integer), and current acceleration (which comes from the total newton force of the 4 wheels, again this is where I start to get very confused). (Then in the test program I am to print out a simulation of this car over a period of 100 seconds, and show its position, velocity, and acceleration at each point (based on the mass, total newton force, and starting position). This part is of course a simple while loop, and is somewhat trivial.)
From what I understand, I will need to allocate memory for all of the data each class holds. Then, using function pointers, as well as #include "X.h" , I will need to somehow link up all of the classes together so that car has access to all of the parts' functions which set, for example, the newton force of each wheel.
We have learned a slight bit about structs, malloc, sizeof, and pointers, but I have not used them to link functionality or data from separate classes together.
Issue 1: I am using a stringstream object in a block of my program that needs to be visited repeatedly depending on a user's selection from a menu. I want the contents of this stringstream object to be cleared any time control gets to this part of the program. I have tried the clear and flush functions to no avail.
Issue 2: I am reading data from a source text file that would be regularly changed during the course of program run. After the program run is over, I am supposed to save the results(which is basically the source text file AND all updates) in a destination file. This destination file would then serve as the source file when next the program is run. In other words, I want a scenario where my results overwrite the original contents of the source file; implying that my source and destination files are now one, pretty much. How can I do this?
I am trying to write a program that will open a file with 2 points, take those points, determine what quadrant those points are in, and save the result back into the same file without truncating the data.
I'm having some trouble with my file I/O. I can't get my program to read the two values for X and Y that I put in the points.txt file. It simply uses whatever random number was used last time in that block of memory. In my points.txt file I put something like "4 -5" and it wont assign those numbers to my X and Y variables. I believe the issue is on line 25
#include <iostream> #include <fstream> using namespace std ; int main() { //defining X and Y double X, Y ;
If I am reading data from a .txt file with a person's last name and first name (e.g. Miller Andrew), How do I output the same data with the first name followed by the last ?(e.g. Andrew Miller) Do I use the ignore function?
I want to know how to read a .pgm file from my hdd and store it in a 2d array so i can perform some action on the array later on. This is ny first time working with an imqge in c so i know nothing about it. .
I have been given a task to make a c++ program that promptsd the user to enter a mp3 file name, read the ID3v1.1 tag and displays it. It then should prompt the user to to decide if they want to edit the comments section of it, then if they edit the section, it should re-print the updated ID3 tag. The list of genres are in a cstring that is as follows.