C++ :: Pointer-based Data Loading From A (text) File
Dec 4, 2013
I have two classes, productListType and buyerListType, that are each basically linked lists. To create the linked list for an object of productListType, I successfully wrote a non-class function createProductList to read the product data from a text file. The class definition for buyerListType has a data member productBoughtRecord that is of type productListType to aggregate the details of the products purchased by a particular buyer during transactions. I decided to make productBoughtRecord a pointer since the contents of this data member would wax and wane over the course of several transactions, depending on the amount and frequency of payments made by the buyer. I have provided a rough sketch of the class below:
class buyerListType
{
public:
setCustomerInfo( ....., productListType* p);
.
.
.
private:
productListType* productBoughtRecord;
.
.
};
I'm similarly trying to write a non-class function createBuyerList to load the record of customers from a text file. How do I determine what the value of the formal parameter p in member function setCustomerInfo is, in order to be able to set the data member productBoughtRecord? take into consideration that an object of class buyerListType would have multiple buyers with varying amounts of products purchased.
View 11 Replies
ADVERTISEMENT
Jan 25, 2015
I am currently working on a project that requires me to "load the data in the file into array at the beginning of the program."
I have a text file with data, and I need to populate an array with the information. From then on, I am supposed to be able to add, display, and search that array. However, I can't figure out how to add the data from the file into an array. I was trying to find out how to search the text file itself. So it threw me off balance and I've been staring so long at the screen I can't really focus.
View 7 Replies
View Related
Jul 19, 2013
I'm having troubles with loading my text file into my array.
Code:
int main(int argc,char* argv[]) {
if(argc!=3) {
printf("
Insufficient arguments
[code]...
I'm also suppose to return the size of the input at the end.
View 3 Replies
View Related
Dec 23, 2014
I have a area in my Project where i need to display a title and content in two text boxes. The Data base tables are:
ID | Title | Content
This is what I have so far, I know I am on the right track, I just cant figure out how to get each box to display based on the ID.
private void frmMain_Load(object sender, EventArgs e){
try {
string connStr = ConfigurationManager.ConnectionStrings["sdcAssistDB"].ConnectionString;
OleDbConnection dbConn = new OleDbConnection(connStr);
dbConn.Open();
[Code] ....
View 3 Replies
View Related
Nov 20, 2014
I have a piece of code that sorts data based on some metric. The some metric is something I now want to make flexible so I can easily switch between and compare metrics. To do this, I want to pass the function to use as a parameter to the method that does the sorting (and other stuff). However, I'm having problems figuring out the syntax. Also, I think my [temporary] organization of code is violating a lot of basic code design principles.
To make the function pointer passable, I defined the "typename" in the header where the function is located (it is part of a struct, "Data"):
// Below the struct definition of Data
typedef double (Data::*CostF)(unsigned l, double W) const;
The two example functions I want to use are defined in that struct ("Data"):
// Inside the struct definition
inline double someExampleCost(unsigned l, double W) const {
// Returns some basic calculation
}
The function that uses it is part of a different class (that holds a reference to the first class, in case that matters; I feel like I'm doing something odd here, because I'm binding a member function in the definition/passing, but never referencing the object). It looks like this:
// Inside another class ("Foo")
inline void DoSomeStuff(double& ECost, double& TCost, CostF cost) {
// Irrelevant stuff here
std::sort(vector.begin(), vector.end(), [&](unsigned a, unsigned b){
return (*cost)(a, W) < (*cost)(b, W);
});
// More irrelevant stuff here
}
The error shown is "operand of "*" must be a pointer". If I remove the '*':
[code]return cost(A, W) < cost(b, W);
the error becomes: "expression must have a (pointer-to-)function type."
The call to this function is, currently, just in the main function, as I'm just testing before I wrap it into real code. It looks like this:
// In main
Foo bar; // Make an object of the struct that has the "sorting" function
CostF costFunction = &Data::someExampleCost;
// Bind to the Cost function bar.DoSomeStuff(varA, varB, costFunction);
This bit shows no errors by itself. So, my questions:
a) Clearly I'm missing the insight into Function Pointers. I'm comfortable with regular pointer stuff, but I can't wrap my head around FPs, partly due to the awkward syntax.
b) I'm very uncomfortable with the fact that I'm binding a member function of a class, but never try to reference an actual object of that class. This is probably a big part of why it's not working, but I can't seem to bind a function belonging to a specific object. I thought of doing
// In the main again
Data d; // Construct the object, which contains big lookup tables
Foo F(d); // Construct the object, which only holds a reference to a Data object
CostF costFunction = &d.someExampleCost; // Bind to the Cost function of that object
but that doesn't work ("a pointer to a bound function may only be used to call the function").
View 4 Replies
View Related
Mar 29, 2013
What is the most efficient (fastest) way to load data from a file on HDD to RAM? (which would allow to only load a limited section of that file - eg. load only half of the file etc.)
View 3 Replies
View Related
Jun 11, 2014
What is the best / most efficient way to load polymorphic data from a file? I thought you could have an enumeration and for each item to load from a file you could have an integer at the start specifying the type of data, but I think there must be a better way I'm just not sure what.
Example of what I mean:
//The syntax isn't really that important for explanation
class base;
class a: base, b: base;
enum polymorphicType {
A,
B
};
and in the loading code you would have (this is the bit I think could be improved):
polymorphicType t;
File >> t;
if(t == A) {
newObject = new A;
} else if(t == B) {
newObject = new B;
}
I think there is probably a more efficient/better way of doing this I am just unaware of it.
View 4 Replies
View Related
Apr 28, 2014
Heres what I am suppose to do, So it doesnt seem hard to understand my messy code!
1. Gotta load the file "FactoryData.txt"
2. Load all values in my 2D array (array[5][3])
3. Print out the array to ensure that the copying went by well.
Heres my problem:
1. The for loops is REALLY off in my eyes. From my knowledge (correct me if im wrong), its suppose to be for(r=0;r<5;r++) not <=. BUT somehow im getting the results I want (in terms of formatting). HERE IS MY OUTPUT
Quote
300 450 500 510
510 600 750 627
627 100 420 530
530 621 730 200
200 50 58 100
100 83 4 5
Press Enter to return to Quincy...
View 8 Replies
View Related
Nov 29, 2014
I'm trying to read a "pointer-based" maze .txt. The first letter in each row corresponds to the room letter...then the letters that follow are North node, East node, South node, and West node respectively. The asterisk indicates an empty room or not a valid option.
Here is what I have come up with, what is happening is after the file is parsed by read_maze it is calling my is_empty function indicating that there is no maze because it doesn't go into the else statement here.
I've attached a sample input file:
maze.txt (130bytes)
Number of downloads: 19
We can't assume the rooms will be in order alphabetically A - Z, We are expecting a maximum of 12 rooms and there is a space between each letter or asterisk.
void Maze::read_maze(string FileName){
string line;
ifstream inStream;
inStream.open(FileName.c_str());
int test = inStream.peek();
int i = 0;
if (!(inStream.fail())){
while (!inStream.eof() && test != EOF){
[code]....
View 5 Replies
View Related
Nov 5, 2014
Here is the assignment... Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :
Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110
Generate the output in the following format :
John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior
The program must be written to use the enum class_level :
enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;
and define two namespace globalTypes (tys and fys) for the function :
class_level deriveClassLevel(int num_of_credits) ;
The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.
The first namespace globalType tys should derive the class level based on a two year school policy. And the second namespace globalType fys should derive the class level based on a four year school policy.
Four Year School Policy:
Freshman 0-29 creditsSophomore 30-59 credits
Junior 60-89 creditsSenior 90 or more credits
Two Year School Policy:
Freshman 0-29 creditsSophomore 30 or more credits
and this is the code I have so far...
#include <cstdlib>
#include <iostream>
#include <cctype>
#include <fstream>
using namespace std;
enum class_level {FRESHMAN, SOPHOMORE,JUNIOR,SENIOR};
class_level classLevel;
[Code] .....
My main question is did I use the namespaces and enum correctly? And my second question is whats the best way to input the data from the text file? This is really where I get stuck.
View 3 Replies
View Related
Nov 7, 2014
Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :
Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110
Generate the output in the following format :
John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior
The program must be written to use the enum class_level :
enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;
and define two namespace globalTypes (tys and fys) for the function :
class_level deriveClassLevel(int num_of_credits) ;
The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.
The first namespace globalType tys should derive the class level based on a two year school policy.
The second namespace globalType fys should derive the class level based on a four year school policy.
So I basically did it in parts and got everything working and then had to make the namespace so I had this:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
[Code] ......
I know I have to clean it up and change it but it ran like it was suppose to. Then I tried adding the global namespaces and I this:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
class_level classLevel;
[Code] ....
with this i keep getting an error saying tys::deriveClassLevel: must return a value and tys::fys::deriveClassLevel: must return a value. I have been messing around with this part and struggling I thought I used the namespace to run the if statements with the criteria for the years of school. Basically I have been stuck for awhile and trying to change things around but I cant seem to get it to work.
View 2 Replies
View Related
Apr 24, 2013
I want to create a binary file based on some hex data :
Ex Input Hex :54313032202020303030
Out put like :6
View 2 Replies
View Related
Dec 22, 2014
I'm trying to make a Quiz program based on C++'s Data File Handling capablities. I've attached the code in .txt file and I wonder why I'm getting the error identifier bScience cannot have a type qualifier?
Attached Files QuizPro.txt (9.6 KB)
View 7 Replies
View Related
Nov 11, 2014
Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :
Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110
Generate the output in the following format :
John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior
The program must be written to use the enum class_level :
enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;
and define two namespace globalTypes (tys and fys) for the function :
class_level deriveClassLevel(int num_of_credits) ;
The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.
The first namespace globalType tys should derive the class level based on a two year school policy.
and the second namespace globalType fys should derive the class level based on a four year school policy.
Four Year School Policy:
Freshman 0-29 creditsSophomore 30-59 credits
Junior 60-89 creditsSenior 90 or more credits
Two Year School Policy:
Freshman 0-29 creditsSophomore 30 or more credits
NOTE : use ignore() function with ifstream objects whenever you want to ignore the newline character.
For example :
ifstream transferSchoolFile ;
transferSchoolFile.open("student_status.txt", ios::in);
while( !transferSchoolFile.eof()) {
getline(transferSchoolFile,name) ;
transferSchoolFile >> id >> credits;
transferSchoolFile.ignore(); //Used here to ignore the newline character.
….
}
I did this in parts so I got it working with a four year criteria without the user defined name spaces.
include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
[Code] ....
So that worked fine then I tried with name spaces -
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
enum class_level { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
class_level classLevel;
[Code] ....
I know I have some stuff to mess around with but I am currently stuck with two errors, first -
Error1error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartupC:UsersstephenDocumentsVisual Studio 2013ProjectsinputConsoleApplication1MSVCRTD.lib(crtexe.obj)ConsoleApplication1
then -
Error2error LNK1120: 1 unresolved externalsC:UsersstephenDocumentsVisual Studio 2013ProjectsinputDebugConsoleApplication1.exeConsoleApplication1
View 1 Replies
View Related
Nov 11, 2014
Program Description: Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student's name (lastName, firstName middleName), id, number of credits earned as follows :
Doe, John K.
3460 25
Andrews, Susan S.
3987 72
Monroe, Marylin
2298 87
Gaston, Arthur C.
2894 110
Generate the output in the following format :
John K. Doe 3460 25 Freshman
Susan S. Andrews 3987 40 Sophomore
Marylin Monroe 2298 87 Junior
Arthur C. Gaston 2894 110 Senior
The program must be written to use the enum class_level :
enum class_level {FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } ;
and define two namespace globalTypes (tys and fys) for the function :
class_level deriveClassLevel(int num_of_credits) ;
The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.
The first namespace globalType tys should derive the class level based on a two year school policy.
and the second namespace globalType fys should derive the class level based on a four year school policy.
Four Year School Policy:
Freshman 0-29 creditsSophomore 30-59 credits
Junior 60-89 creditsSenior 90 or more credits
Two Year School Policy:
Freshman 0-29 creditsSophomore 30 or more credits
NOTE : use ignore() function with ifstream objects whenever you want to ignore the newline character. For example :
ifstream transferSchoolFile ;
transferSchoolFile.open("student_status.txt", ios::in);
while( !transferSchoolFile.eof()) {
getline(transferSchoolFile,name) ;
transferSchoolFile >> id >> credits;
[Code] ....
I know I have some stuff to mess around with but I am currently stuck with two errors, first -
Error1error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartupC:UsersstephenDocumentsVisual Studio 2013ProjectsinputConsoleApplication1MSVCRTD.lib(crtexe.obj)ConsoleApplication1
then -
Error2error LNK1120: 1 unresolved externalsC:UsersstephenDocumentsVisual Studio 2013ProjectsinputDebugConsoleApplication1.exeConsoleApplication1
View 2 Replies
View Related
Apr 19, 2013
I want to input data into text file while not deleting the original data in the file and I use something as
ofstream writefile;
writefile.open("example1.txt");
if (writefile.is_open()) {
for(j=0; j<N; j++) {
[Code] ....
But this will delete the original data.
View 3 Replies
View Related
Mar 31, 2014
I am creating a simple log parser (loads a text file and filters out unnecessary information, but has the option to show the full log) and I'm running into an issue with fairly large log sizes (50+mgs). I have seen a few recommendations from a stream to memory manged files and even alternate 3rd party controls.
I foresee a few issues with any of the non-third party solutions (which I would prefer to avoid third-party add-ins) such as the scroll bar not correctly reporting the relative length or position of the complete text in the box (when displaying only a portion of the file at a time) and in the stream solution where you read on scroll (as necessary) have not only the same issues, but how do you resume reading in the middle of the file? This also all assumes I would be periodically clearing the RichTextBox to keep the memory usage down to avoid an OutOfMemoryException (which I have been running into.)
View 14 Replies
View Related
Feb 25, 2014
I'm trying to solve the ferry loading problem using two queues. My problem is I can't enter in data after the first set is scanned in, I'm assuming there is a problem with my loop, such that the scan function doesn't get called after one iteration. In the example I marked the data I can't enter. An example correct input would be:
correct input:
1 - can enter data20 4 - can enter data
380 left - can enter data
720 left - can't enter data
1340 right - can't enter data
1040 left - can't enter data
correct output: 3
my incorrect output: 1
Code:
#include <stdio.h>
#include <stdlib.h>
#include "my_linked_list.h"
#include "my_linked_list.c"
#include "status.h"
[Code] ....
View 6 Replies
View Related
Nov 24, 2013
I have this code for a computer project... (store management) but the character strings are not copied on text file..
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class Store {
public:
char *item_name[5];
store()
[Code] .....
Now when i run the program, it gives a error :::
ERROR
address 0x0
How can i write these strings to the text file?
View 2 Replies
View Related
Nov 3, 2014
So for a project, my professor sent out two pages of code containing functions to read a text file (since we do not know how to write this on our own yet). I've got the code working on Orwell IDE and it gives me 2 warnings saying
"Passing argument 1 of 'readFromFile' from incompatible pointer type"
"Passing argument 2 of 'option2Print' makes integer from pointer without a cast"
The Orwell IDE seems to just bypass these warnings and compiles the code correctly. However, when I transferred my files over to my desktop using BloodShed (what the professor uses), instead of getting a warning I get an error and the code won't compile.
I assume it will not compile on his computer either since he uses the BloodShed IDE.
I don't know how to put the code directly into the text neatly, so a attached a .zip file with my code. The "storms.txt" file is also included. (the file that will be read).
View 4 Replies
View Related
Mar 27, 2014
I have a program I have to do that counts the number of words in a text file. I have tried the code on 2 computers now since my programming teacher told me the code was fine. Here is my code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream infile;
infile.open("tj.text" , ios::in);
[Code] .....
View 4 Replies
View Related
Feb 25, 2013
I wanna read data from txt file with space divided each value like
1.00518 2.01903 3.01139 4.01343 5.02751 5.99913 7.00011 7.99851 8.99506 9.98015 10.9901 11.992 12.9923 13.9932 14.996 16.0034 17.012 18.0255 19.0366 20.0485 21.0505 22.0664 23.0455 24.0383 25.0374 26.0439 27.0378 28.0376 29.0576 30.066
I know the size of the data is 2*500.
In matlab I can use like
fid = fopen('example.txt');
data = fscanf(fid,'%f,',1499500);
how should I write in C++?
View 3 Replies
View Related
Jan 14, 2013
I need to copy data from one text file to another.This is how data in file looks like:
2 -3 8 5 0
3 5 1
2 -2 3 1 7 6
5 -3 15 0 1
I succesfully managed to copy those numbers but with one mistake.The last number is written twice. My output file looks like this:
2 -3 8 5 0
3 5 1
2 -2 3 1 7 6
5 -3 15 0 1 1
This is my code:
int a;
string str;
stringstream line;
[Code]....
View 3 Replies
View Related
May 5, 2014
read some information from a text file. The program I'm working on is like a simple betting program.
What I need to read are:
match_code - team1 - team2 - odd1 - odd0 - odd2
139 Atletico Madrid - Real Madrid 2.853.40 2.35
But the spaces between datas are not known. We only know that both team names may contain more than one word and there is one space, exactly one dash and one more space (" – ") between team names.
Also match_code is an int and odds are double values.
while(getline(input, line)) {
istringstream ss(line);
ss >> match_code >> team1;
string temp;
while(ss >> temp) {
[Code] .....
In that missing part, I need to get the second word of team name if there is one; and the three odds that are odd1 odd0 and odd2.
View 2 Replies
View Related
Feb 10, 2015
Each line of the text file has first name, last name, and a salary. Something along the lines of this:
john doe 4000
bob miller 9000
I want my program to take the first name, last name, and salary of each line and assign them to strings. I have tried this so far:
while (inFile){
inFile >> firstName;
inFile >> lastName;
inFile >> grossPay;
cout << firstName << " " << lastName << " " << grossPay << endl;
}
When it outputs the names and the salary, the last line of the text file gets output twice by the program.
View 1 Replies
View Related
Aug 26, 2014
Requirements in filtering the text file.
1. first my professor required me NOT to change the MAIN function(because he made it)
2. I have to make 3 getlogs() STRING FUNCTIONS:
a. string getlogs(); - accepts no paramters, SHOWS ALL THE CONTENTS OF TEXT FILE
b. string getLogs(const string & a); - accepts 1 parameter -SHOWS ONLY THE LINE WHICH CONTAINS THE SPECIFIED DATE FROM MAIN FUNCTION which is "2014-08-01"
c. string getLogs(const string & b, const string & c); - accepts 2 parameters, SHOWS ONLY THE LINES FROM THE DATE START to DATE END specified at THE MAIN FUNCTION which is date start-"2014-08-01";DateEnd = "2014-08-10";
3. all COUT should be in the MAIN FUNCTION
TEXTFILE CONTAINS:
2014-08-01 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-02 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-03 06:13:14,Name,4.5,CustomUnit,CustomType
2014-08-04 06:13:14,Name,4.5,CustomUnit,CustomType
[Code] .....
my codes so far:
//MAIN
#include <iostream>
#include <string>
#include <fstream>
#include <dirent.h>
[Code].....
View 1 Replies
View Related