C++ :: Storing File Data In Array With Structure Type?

Feb 20, 2015

I have a structure

struct Wine
{
string wineName;
int vintage;
int rating;
double price;
};

how can i store the file data below in an array with the structure type???

Dow Vintage Port ;2011;99;82
Mollydooker Shiraz Carnival of Love ;2012;95;75
Prats & Symington Douro Chryseia ;2011;97;55
Quinta do Vale Meão Douro ;2011;97;76
Leeuwin Chardonnay River Art Series ;2011;96;89

View 1 Replies


ADVERTISEMENT

C :: Storing File Data In A Structure Of Format Shown

Aug 5, 2014

I'm having trouble reading my data from a .txt file into a structure of the format shown in my code. I've made my student database in the program below based on user input and I didn't have a problem with that, but now it's come to input from a file it's making it difficult.

My three tasks are:

(1) A table containing 1 row per student, containing the student ID number and all of the student's marks.

(2) Another table, containing 1 row per student, containing the student ID number and the average mark obtained by that student.

(3) The average mark for each subject.

The assumptions to be made are: The student ID can begin with a zero, and should therefore be read in as a string.The test data will contain 20 students but the program should be able to deal with up to 100 students.Assume there are no more than 4 different subjects.

So based on the first assumption I've arranged the data in the file in an order in which the student ID begins with a zero:

003953 Computing 38
003953 English 88
003953 Mathematics 29
003953 Physics 83
073241 Computing 63
073241 English 99
073241 Mathematics 32
073241 Physics 73

...for twenty students, 80 lines of data. Now, on the assumption they must be read in as strings, this is what's making it tricky to store in the structure because, I've got 80 ID numbers but 20 repeat themselves 4 times. Once I've got this data in the structure below the tasks I won't have a problem with because I can just base it on a user input program but the data's already stored instead.

Below is my code for user input associated with task (1). In this example the IDs are stored as ints but for the file they will be strings. It compiles fine, displays the data as shown in the assignment sheet, but I don't know how to get the data into my structure. I can store the data in a structure of three arrays using fscanf() no problem, but it's not very "workable" for what I need to do with it.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

[Code].....

View 11 Replies View Related

C :: Filling Structure Client / Storing Different Instances In Array

Mar 31, 2013

Here is what I have going on.

Code:

struct client {
char firstName[stnd];
char lastName[stnd];
long ID;
char email[stnd];
float funds;
float wager;
}

typedef client...I would like to have these fields filled with this function below and stored in an array... Basically Multiple users and this is my function for it, if I can get it to work proper -.- .... I don't get syntax errors but I do get warnings

Code:

void getct(client *cl, int *pclientCounter) {
char input[buff];
char *pinput = NULL;
int typef = 0;
int lengthf = 0;
}

[code]....

View 3 Replies View Related

C/C++ :: How To Create Objects Of Same Data Structure (type)

Dec 31, 2014

well i create a State.h class

#ifndef STATE.H
#define STATE_H
class State {
public:
virtual void handle_action() = 0;
virtual void update() = 0;
virtual void render() = 0;
};
#endif //STATE.H

What i'm trying to create is a simple State Manager for SFML! I created another class that inherits State.

#pragma once
#include "state.h"
class FirstState : public State {
public:
FirstState();
~FirstState();
void handle_action();
void update();
void render();
};

So the question is this, each state that i have will inherit the State class. However, i wanted to perhaps add each state object into a vector array. But i'm not sure as to what data type it be? I have a state manager class that will contain the vector.

What i want to do is this, each game state will create an object that will inherit functions from the state.h class. I want to store them all in a vector array, but each object is clearly named different. My curiosity was wondering, since all those different states inherit the State.h class, can i simply create a State Object std::vector<State> *states; that will contain all those different state objects?

[URL]....

View 1 Replies View Related

C++ :: Structure Record Type In Array

Feb 24, 2015

I have to enter the Instructor ID and invokes getFees to find the fees of the given instructor. Then it will displays the message that shows either the fees or "No such instructor ID" if not found. the function prototype is

double.getProfessionFees(string);
#include <iostream>
using namespace std;
const int DECLARED_SIZE = 7;
int search(const int a[], int number_used, int target);
struct InstructorType

[Code]....

View 7 Replies View Related

C++ :: Structure Record Type In Array - Unresolved Structures

Feb 25, 2015

Why I do have this error message?

1>------ Build started: Project: TMA04, Configuration: Debug Win32 ------
1>TMA04.obj : error LNK2019: unresolved external symbol "double __cdecl getFees(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?getFees@@YANV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
1>C:UsersEvgericDocumentsVisual Studio 2010ProjectsTMA04DebugTMA04.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

View 1 Replies View Related

C++ :: Storing Data In A File?

Apr 12, 2013

I am trying to store the Title, Artist, and date published of a list of CD's. I can't seem to be able to get it to print the list or not sure if it is actually storing it. This is what i have so far.

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main() {
char names[5][100];

[code]....

View 2 Replies View Related

C++ :: Reading And Storing CSV File Data

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

C++ :: Reading Data From File Then Storing It To Reuse?

Mar 27, 2013

Im tasked with reading a data file, this is an example snippet

list of trophy winners
year facup leaguecup 1stdiv 2ndiv
1960/61 Tottenham Hotspur Aston Villa Tottenham Hotspur Ipswich Town
1961/62 Tottenham Hotspur Norwich City Ipswich Town Liverpool
1962/63 Manchester Utd Birmingham City Everton Stoke City

The file starts in 1892 and is up to 2011/12, there is data missing for some years due to the wars etc,

once ive read the file, i need to store the data, for me to re-use.

There are a lot of useful link regarding reading data in, but they tend to be with very small files with say 10 lines of numbers.

View 1 Replies View Related

C++ :: Bank Account - Function Not Storing Data In Array

Mar 5, 2014

Following function is from a bank account, when new account is created it won't store it in the array or i guess it does but find_acct function wont be able to find it.

find_acct Function:

int findacct(int acctnum_array[], int num_accts, int requested_account) {
for (int index = 0; index < num_accts; index++)
if (acctnum_array[index] == requested_account)
return index;
return -1;

[Code] ....

View 2 Replies View Related

C++ :: Reading File With Delimiter - Storing Data To Object

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

C :: How To Store Data Structure Into 2D Array

Mar 22, 2013

I have this data store into a data structure.

i j x y w h w*h
0 0 0 0 9 11 99
1 0 0 11 9 10 90
2 0 0 21 9 11 99
0 1 9 0 8 12 96
1 1 9 12 8 7 56
2 1 9 19 8 6 48

[Code]...

Code:

struct data {
//Here
/*! horizontal position */
int x;
/*! vertical position */
int y;
/*! width */
int w;
/

[Code]...

data and then i have an array /*! it contain group_id of each data line*/ int group_id[16]={0,0,0,0,3,3,1,1,1,3,3,2,2,2,2,1}; I never worked with 2D array before. My problem is that i want to create a 2D array of that data for example if i write data[j][i].. It will give me the reference/value of all data lines that belongs to j column, and same with group_id[j][i]. I don't know how i can store these structure vaules in this like 2D array.

View 2 Replies View Related

C :: Implementing Trie Data Structure With Dynamic Array

Jun 23, 2013

i can't implement trie with dynamic array .the problem is in this line i think :

Code:

childs_size = (node_p -> childs_value_p)[0] + 1; here is my code : Code: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct trie_node {
unsigned char *childs_value_p; // pointer to an array of child nodes value
struct trie_node **childs_ptp; // pointer to an array of child nodes pointer
struct trie_node *failure_node_p; // pointer to failure node

[code]...

i could write this code with binary tree instead of dynamic array but need a large amount of memory for about 13000000 strings of length 16 . is there any better solution with lower memory usage to implement trie ?

View 8 Replies View Related

C :: Storing A Value In Array From Reading In From A File

Sep 12, 2013

Is something like this possible and if not how can I make this work?

fscanf(in, "%d %d %d", &i, &x, &arr[i+x]);

View 4 Replies View Related

C++ :: Reading Integers From File And Storing Into Array?

Oct 28, 2014

My main issue is that when I store just one value into a simple integer variable, it gives me a big negative number.

My goal is to store a file that reads like this into arrays:

2014 1 23
2012 2 15
2013 1 25
etc

Where I would have the first column in an array, the second in another and the third in third array since I am not allowed to use multidimensional.

View 5 Replies View Related

C/C++ :: Reading Input From A File And Then Storing It Into Array?

Feb 16, 2015

I need to read input from a file , which contains multiple sentences of varying lengths. After each new line char, i need to store that sentence into an array.

#include <iostream>
#include <cstring>
#include <fstream>
#include <cstdlib>

[Code].....

View 2 Replies View Related

C++ :: Possible To Use Data Type Double Or Float For Array?

Mar 9, 2014

Can you use data type double or float for an array? ie

double n[];
or
float a;
float m[a];

My code wont accept me changing the data type..will on accept int data type. I get the following error when I try to change the array to double or float..

3310E:C++vector.cpp[Error] invalid types 'double [1000][double]' for array subscript

View 4 Replies View Related

C :: Error To Define Data Type File?

Mar 21, 2013

I program unix sokcet programming , and part of my code is ti open file from server and open it , but i surprised with this wierd error i dont have any reason for it ?

Code:
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>

[Code] ....

File name is : myHeader.h
myHeader.h:24:1: error: unknown type name "File"???

View 1 Replies View Related

C :: Reading Lines From A File And Storing It In Array From Typdef Struct

May 4, 2013

I'm trying to read in lines for a file and storing it in an array. This is what I have so far. Am I allocating the memory correctly?

Code:

typedef struct {
/* declartion of variables */
} App
typedef struct {

[Code].....

How do I access the array content? I'm suppose to strtok the contents from the lines stored in the array and use it again.

View 2 Replies View Related

C++ :: Reading Info From A File And Put Data Into Vectors Of Its Appropriate Type

Apr 4, 2013

I'm trying to read information from a file and put the data into vectors of its appropriate type. For example: the file will have an int ID, string firstname, string lastname, double salary, int hours_per_week, and string work_position. All this data is separated by ";". I don't know how to read this file into the appropriate vectors: vector<int> ID, vector<string> fname, vector<string> lname, vector<double> salary, vector<int> hpw, vector<string> work.

View 8 Replies View Related

C++ :: Read Phone Number Into Array And Can't Use String Data Type

Jan 13, 2013

I have an assignment where I need to read in a phone number into any array and I can't use the string data type. Assuming I need to use the getline function, how do I do this? I'm guessing it's with the cstring or .c_str() functions? I don't know.

View 4 Replies View Related

C++ ::  Storing Static Class Members Of Dynamic Variable Type In DLL

Oct 15, 2013

How I can implement it.

Tickable.h

#include <list>
#ifdef TICKABLE_EXPORTS //Automatically defined by MSVS
#define DLL __declspec(dllexport)
#else
#define DLL __declspec(dllimport)
#pragma comment(lib, "Tickable.lib")
#endif

class DLL Tickable{

[Code] ....

error LNK2001:
unresolved external symbol "private: static class std::list<class Tickable*,SKIPPED BITS> Tickable::subs" HUGE_SYMBOL_LIST
PATHTickable.obj

I know with such a tiny and insignificant class the dll export seems pointless but this class is actually intended to be a .lib ONLY. But it is derived from by .dll style classes, and through inheritance this error is the exact same as what appears in the derived class, I just imagine that the cut down version would be easier to work with.

Is it possible to hold either a static variable in a dll which is of a dynamic type, OR would it be possible to reference an external variable which is static throughout the instances and this variable can be chucked away in a namespace of mine somewhere?

I suppose my only other option (if this is possible) would be to define a maximum instance number and create a standard array of pointers but this could both waste so much memory when not in use and cause problems if I need more memory.

View 5 Replies View Related

C++ :: Create Main Function With One Dimension Dynamic Array With Float Data Type

Dec 4, 2013

I need to create a main function with a one dimension dynamic array with float data type. The total number of array elements must be controlled by a user input from the keyboard. Test data is three different lengths 3,6,9 of the array. The lengths have to be set up at run time from users input. I understand how to create dynamic array but not where the user inputs the length of the array. How would I implement this?

View 6 Replies View Related

C/C++ :: Copy Content Of File Into Structure Array

Feb 8, 2014

I am trying to write a program for a library system that allow stuff to add, remove, view and delete customer. i try to use file to store data and i open the file in mode read then i store then i put the content of the file into a structure. now the problem started it is only showing me haft of the content and here is the coding.

#include <stdio.h>
# include <windows.h>
# include <stdlib.h>
#include<string.h>
#include<conio.h>    
void search(int s,struct books eli[20]);
void view(int x,struct books eli[20]);    

[Code] .....

View 1 Replies View Related

C/C++ :: How To Get Array Of Structure Code To Read Form A File

Dec 10, 2014

I tried to make the program read from a file text the first name or last name but o cant seem to get it. i tried alot of different ways. how can i get the array of structure code to read form a file?

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
const int NUM_STUDENTS = 17;
const int NUM_QUIZZES = 10;
const int NUM_EXAMS = 5;

[Code] .....

View 14 Replies View Related

C++ :: Returning A Structure As Function Return Type

Apr 4, 2013

I am having problems with my function definition of a function that should return a structure value.

This is the error I get compute.cpp(9): error C2146: syntax error : missing ';' before identifier 's_advertisebus'

The error is on the line where I start my function definition typing my function type as a structure. A long time ago in c the keyword struct is used with the structure type like struct s_advertisebus s_readadbus(). I tried it both ways but I got errors.

// struct.h
#ifndef STRUCT_H
#define STRUCT_H

struct s_advertisebus {
int nnumberofads;
float fpercentused;

[Code] ....

View 2 Replies View Related







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