C++ :: Reading All Data For Object
Apr 15, 2014
All i need is to create a "read" function to read all the data for a Player Object.
So Far i made a display function to display all the data for the "Player" object, but i don't know how to make a read function.
Here is my program:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include "player.h"
[Code] .....
View 3 Replies
ADVERTISEMENT
Dec 5, 2014
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";
[Code] .....
View 5 Replies
View Related
Feb 6, 2014
I am wanting to be able to add as many different instances of data, while the user has not stated 'n', but then it only ever writes back to the screen the input for the last set of data. Where as I want to display back to the screen all the data that has been entered.
Code:
#include <iostream>
#include <string>
/*Function Declaration*/
void createItem();
void returnItem();
//Items structure
[code]...
View 6 Replies
View Related
Oct 8, 2013
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.
View 1 Replies
View Related
May 15, 2014
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.
View 1 Replies
View Related
May 24, 2014
How do you create an object (like in the title) something more simple than a struct? I wanna know that cuz I'm writing a function that could return a boolean and an integer at the same time.
View 2 Replies
View Related
Jan 29, 2015
I've downloaded a Sage 50 2014 data object and added a reference to it in my project. I'm able to connect to the Sage Account package using:
SDOEngine sdoEngine = new SDOEngine();
WorkSpace workSpace = sdoEngine.Workspaces.Add("MyCompany Limited");
try
[Code].....
View 4 Replies
View Related
Dec 14, 2013
I am writing a program that manages a group of tool bins. This group is handled as an object that is an array of two element structures called InvBin. I initialize the bins with data from a file which contains the descriptions and initial quantities. I also have functions to add or subtract items from a bin and a function to display a report of the description and quantity of all of the bins.
The add and remove functions work correctly based on the cout statement in the functions, however when I display the report, it displays the initial quantity instead of the new quantity. In addition, when I use the add and remove functions again on the same bin, they use the initial quantity.
These are the add and remove functions and the report function from the main program.
Code:
//Adds an item to a bin
void addItem(HANDLE screen, BinManager tools, int &count) {
int binNum;
int addNum;
system("cls");
[Code].....
View 2 Replies
View Related
Dec 21, 2013
I have an abstract class Base, with derived classes Derived1, Derived2, etc. I don't know how many there are. So, I have declared an object of Derived like so:
Base* der1 = new Derived1(/* constructor details */);
That gets passed to a function, which modified the data contained by this pointer. However, I need to keep the data from the object, which means that I need to copy the data somehow. The problem is, this copying needs to be done within the function, due to the requirements of the program. I do not know what type the object is, This function will need to reset this data potentially hundreds of times, so I can't just provide lots of objects, as either the function will run out of objects to call or I will run out of space in memory.
How would I create a copy of this, so that I would be modifying a temporary object that could be deleted and I would keep the data that I started with?
View 4 Replies
View Related
Feb 26, 2012
Basically, I've got one object which has to access private data in another object... and can't.
Here's the specifics: I'm writing a little war game program where players deploy units (soldiers, tanks, planes, etc.) onto a gameboard. Players and Units are modeled as objects:
Code:
class GameUnit {
public:
string GetName() {return Name;}
protected:
string Name;
};
class Player {
[Code] ....
Here's the problem: In the above code, Player's ListUnits() function doesn't work because Player can't access GameUnit's GetName() function.
Specifically, here's the compiler's error message:
Code:
In file included from Main.cpp:18:
Player.h: In member function 'void Player::ListUnits()':
Player.h:47: error: 'GetName' undeclared (first use this function)
Player.h:47: error: (Each undeclared identifier is reported only once for each function it appears in.)
I've tested enough to realize that the problem is the GameUnit::GetName() function is a public function within the GameUnit object. Why can't a Player call this function? Making both friend classes of each other doesn't work.
View 3 Replies
View Related
Nov 12, 2013
How does an object access its private data members in copy constructor.
The relevant part of the code: Code: C::C(const C &obj)
{
x = obj.x;
y = obj.y;
}
Normally the object1 called "obj" cannot access its private data members outside. But in this situation it can access. How can it be explained?
Here are the complete code:
Code:
#include <iostream>
using namespace std;
class C{
public:
C(int,int);
C(const C &);
[Code] .....
View 7 Replies
View Related
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
Mar 19, 2014
#include <iostream>
#include <string>
using namespace std;
class book {
private:
string bookname;
double bookprice;
public:
book(string k="calculus",double b=25.5)
{ bookname=k;
bookprice=b;
}
View 2 Replies
View Related
Sep 20, 2012
class CPop {
CBSVector<CTour> pop;
CBSVector<double> probability;
int popsize;
double TotalFitness;
CTour Elite;
CTspGAParams GAParameters;
}
error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'
I don't know y these errors, it runs fine in simple c++ environment
View 14 Replies
View Related
Apr 14, 2014
I'm having a problem trying to modify my patient's data. It seems to work, but once the block of code ends it does not save to the linked list.
Problem located in case M.
linked list template header: [URL] ...
patient header: [URL] ...
patient implementation: [URL] ...
#include <iostream>
#include "listTemplate.h"
#include "PatientRecord.h"
using namespace std;
char menu() {
char input
[Code]...
View 1 Replies
View Related
Jun 26, 2012
I am to first increment data members of object that has not created dynamically (i have done with this part),now i have created object dynamically and how to increment its data which i have passed as argument as:
obj3 = new manage(35 , 36)
View 4 Replies
View Related
Jan 7, 2015
I'm absolutely new to C#. I got a code to edit so it can read data from website.
This is the website: [URL] ....
And I would like to read the data from the table from last row 'world' from 1980 to 2013. I have also went through the html to find a tag and i think its this one :
<td class="datacenter2" nowrap onmouseover="highlight(this, '#D6D6D6', 'World,1980')" onmouseout= "highlight"(this, '#F3E9E9','')">
Where i should insert the tag in this code and what to do to run it properly in unity?
and this is the code I must use:
using UnityEngine;
using System.Collections;
using System.Xml;
public class getWEB : MonoBehaviour {
public string data1 = " "; //Light
public string data2 = " "; //Humidity
[Code] ....
View 4 Replies
View Related
May 16, 2013
Error:
--------------------Configuration: nc - Win32 Debug--------------------
Compiling...
cv.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/nc.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
nc.exe - 2 error(s), 0 warning(s)
Compiles with 0 error but on running 2 Errors appear.
I'm Inputting data of an object from user and then inserting it in the link list.
#include <iostream>
//#include <fstream>
using namespace std;
#define LEN 100
////////////////////////////////////////////////////////////////////////////////////////////////////
class employee{
[Code] ....
View 1 Replies
View Related
Jan 21, 2014
I have two puzzling issues I am dealing with.
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?
View 7 Replies
View Related
Jul 16, 2014
So what I'm trying to do is read map data from streamreader, which is very new for me, I already managed to generate maps using code inside the IDE but im very confused on how I would read it from a file. What I'm trying to say is that I understand how to create a map from the map data, but I dont know how to put that map data into text files which would make my job much easier.
My Game1:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
[Code] .....
Tl;dr basically, how would I go about using streamreader to read the map, and include the required commas and curly braces. I have already used Streamreader for other things and failed miserably.
View 4 Replies
View Related
Nov 22, 2014
If i have a data,how to write the code for read this data?
View 1 Replies
View Related
Apr 29, 2013
I'm having issues reading to a 2d array from a file. When I try to read the data from my file into my matrix variable it simply doesn't read anything and leaves the variable unmodified. I've tried just reading the first piece of data in the main function and it doesn't work there either. I'm really perplexed at this point since I've never had an issue reading from a file before. Here's my relevant code:
Code:
int main(int argc, char** argv) {
double matrix[MINSIZE][MINSIZE]={0}, vectors[MAXSIZE][MINSIZE], ans[MAXSIZE][MINSIZE];
FILE * inFile;
inFile = fopen(FILENAME,"r");
if(inFile==NULL){
printf("File does not exist.
[Code] .....
View 4 Replies
View Related
Feb 21, 2013
I am working on a small c++ project where i read from a csv file with information in this format:
string,string,int
string,string,int
string,string,int
And all of the above information is one person. As is "John,Peter,23" is first name, last name, age. When there are multiple people in a csv file how can i parse through and separate the information in a string and int for later use?
View 4 Replies
View Related
Oct 30, 2014
Im familiar with fstream and know how to read in data, given that there is one type per line.
But I have a file that has multiple lines each containing a string (an address) and two double values (latitude and longitude).
Looking for support with the logic part of reading in data and initializing them to member variable.
View 1 Replies
View Related
Mar 20, 2014
The input is in the following format
5
1 2 9.0
1 3 12.0
2 4 18.0
2 3 6.0
2 5 20.0
3 5 15.0
0
1 5
The first number is the number of vertexes in the graph. Then next lines up to 0 are the edges of the graph. With the first and second numbers being the vertexes and the third being how far the edge is between them. Trying to read in the data and store the edges into there locations in the List adjacency for that vertex. This example would make a graph with five vertexes with edges from 1 to 2&3. 2 to 4&3&1 etc. It also stores in the opposites ex 2 1 9.0.
When reading it in and printing it back out it seems that it is only storing the last data entered for that vertex. EX. When trying to print out the data read in i only get 1 3 12.0, 2 5 20.0, 3 5 15.0, ( 4 2 18.0, 5 3 15.0 would show up if `if(i<n)` was removed it is there so it does not show duplicate edges). what I am doing incorrect?
// CSCI 3300
#include <cstdio>
using namespace std;
struct ListCell
{
ListCell* next;
int vertex;
double weight;
ListCell(int v, double w, ListCell* nxt)
[Code]...
View 1 Replies
View Related
Feb 18, 2014
I can't get my program to read the rest of my variables from my data file it will only read the first two and my end of file won't work it keeps continuing on.
879.46
C 400.00
D 100.0
F 525.00
C 450.00
D 500.00
D 1000.00
C 2000.00
D 3000.00
D 3500.00
C 5500.00
C 500.00
B 200.00
C -235.00
D 250.00
H -500.00
D 500.00
E
That's my data it will only read the inital number and C and D but nothing else.
// develop algorithm to balance checking account make transactions
#include<iostream> // required for keyboard and screen I/O
#include<fstream> // required for external file stream
#include<iomanip>
#include<conio.h>
#include<string>
[Code] ......
View 5 Replies
View Related