C++ :: Best Way To Store Data?

Jul 8, 2013

struct Book{
string bookTitle;
string ISBN;
string author;
string publisher;
string dateAdded;
int qty;
double wholesale;
double retail;
};

What's the best way to store multiple of the above structure?Ideally, it would be with a binary output, but that isn't possible with the strings, unless I'm missing something. So that leaves me with two options.

-Create a second structure that has an outrageous char[] length, and then copy the data from the original structure to write/read to/from the file. The flaws I see in this is excess runtime with copying, and a larger amount of memory is temporarily needed. The positive I see is I can use binary output, which is easier.

-The second option is to just use an ASCII file, and put each element on it's own line, and then just use getline to read each line. The flaw I see in this is that I have to read the file into the structure, instead of just reading the structure and the file can be tampered with (Not a huge concern). The positive is the lack of negative from the above.

View 4 Replies


ADVERTISEMENT

C :: Store Data In Binary File Then Use It To Find Inverse Of Matrix Form Of Data

Dec 6, 2013

I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.

Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();

[Code] ....

View 4 Replies View Related

C++ :: Add Data To Text Files Which Are Required To Store 3D Scan Data

Jul 10, 2013

I have written the following code to add data to text files which are required to store 3D scan data (I have to calculate the y-coordinate). My code seems to work except that it stops working when I want to create more than ten text files i.e. the directory I am trying to store them in will not hold any more than ten text files. Code is shown below.

#include <string>
#include <locale>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

[Code] ....

View 1 Replies View Related

C :: How Data Actually Store In File

May 19, 2014

How data actually store in the File. Like do data store just in one line or at different places for example in array data store in adjacent memory block while in struct data store at different memory block.?

View 2 Replies View Related

C++ :: Using Arrays To Store Data?

Mar 25, 2013

start writing a program to store some information and then have it recalled. I would like to be able to store a list of the video games I own because i thought it would be fun :)

View 1 Replies View Related

C++ :: How To Store Data Into Array

Apr 18, 2013

How can I store this data into an array?And I only can read the first integer.. 10.... How can I read the whole file...Heres the data:

10 alice 4/23/1972 123-45-6789 support assistant
3 bob 6/7/1980 111-12-1134 logistics manager
1 carol 10/2/1963 987-123-1143 admin ceo
2 dave 10/3/1974 902-22-8914 admin cfo
17 erin 6/13/1991 126-83-1942 technology supervisor
15 frank 2/22/1987 303-12-1122 logistics assistant

Heres what I have so far?

#include <iostream> //Accesses libaries for console input and output
#include <fstream> //Needed to access the fstream object to read files
#include <string> //Needed to access the string class
#include <cstdlib>

[code]....

View 1 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++ :: How To Store Data From A Class Into A Container

Feb 10, 2013

I'm having trouble understanding on how to actually store into a container from another class. Any simple example.

View 9 Replies View Related

C++ :: How To Store And Retrieve Data In Class

Aug 20, 2014

I have a class I use to store column data read from delimited text files.

Code:
class column_data {
// class functions here
public:
// initialize class members
column_data()
: header(""),

[Code] ....

Each column is read into the vector of string. Next the string data is copy converted to the vector of double or the vector of int depending on the data type. There can also be additional transformations of the data (normalization, scaling, etc) and the transformed data is copied to the transformed_double_data vector. I do end up with multiple copies of the data, but I can clear some of the vectors if I don't need all the versions of the data anymore. Each column object goes into a container like a vector of objects or map of objects depending on how I need to access the column data.

There are functions that calculate statistics on the data in the columns and the results are assigned to the object variables like validate_r2. There are separate statistics for each column, so it seems logical to store the results in the column object. This works well for statistics like validate_r2 (pearson's correlation coefficient).

The current issue is that I have other statistics like "pw50" that I need to calculate and store. The statistic is the percent within +/- 50 units and the request for pw50 is passed in from the command line. The issue is that there could be several of these and they can have more or less any value like, pw50, pw75, pw100, etc. Storing data like this doesn't fit into my scheme very well because I can't pre-declare a variable to hold the result for every possible option. I don't know in advance how many, if any, of these there will be. I was thinking of adding two vectors, one of string and one of double,

Code:
class column_data {
public:
// initialize class members
column_data()
: header(""),
type(""),
use(""),
validate_r2(0.0),

[Code] ....

For each of this type of statistic requested, I would push_back a label into the string vector and then put the result into the parallel position in the double vector. This seems like I would work, but there are probably some things that could be done with pointers that might be better. Another option would be a vector of objects where each object had a string value for the label and a double for the result. That would be more bullet proof as far as keeping the label and value together, but I have not ever nested objects in a class like that so I thought I would post. I don't know the syntax for declaring an object of class_b inside the definition of class_a. The need is to provide dynamic storage for an unspecified number of these statistics and a reliable way to retrieve the values using the label.

View 1 Replies View Related

C++ :: How To Store Data By Descending Order Auto

Oct 27, 2014

I wanna store my data by descending order auto without doing a classification after , i have come up with a code but it crashes.

Code:
void list::create(int num) {
struct node * n,*temp;
n=new node;
n->data=num;
if(head==NULL)

[Code]....

I don't wanna use the list library with the push.buck, i need to do it by coding it without fix functions ....

View 3 Replies View Related

C :: Gradebook Program - How To Store And Access Data

Jun 15, 2013

How I would store all the data. Also how would I access it after I store it. Side Note we are not allowed to use structures or objects.

For the purposes of this gradebook you should first provide a menu with the following options

-Add a new course Add a new student to a course Add grades for a student in a course Print a list of all grades for a student in a course Print a list of all students in a course Compute the average for a student in a course Compute the average for a course Store Gradebook (to a disk file) Load Gradebook (from a disk file)
-Each of these menu items should correspond to a function you will write.
-For the basic program each student will be represented by an ID number And each course by a course number
-Grades will be whole numbers only (no fractional part)

As indicated in the menu you will need to store and load using a disk file so that the data is retained.

Here are so limiting values in defining your data structures: Maximum Number of students (total) 100 Max number of courses 25 Max number of courses per student 4 Max number of grades per student per course 10

View 6 Replies View Related

C/C++ :: Store Data From A File Into Array Of Structs

Mar 10, 2015

That;s what i have so far: problem: the output data is not correct.

input file
1301 105515018 "Boatswain" "Michael R." CSE 230 ="R01"
1301 103993269 "Castille" "Michael Jr" CSE 230 ="R03"
1301 103993267 "Castille" "Janice" CSE 230 ="R03"

[Code]....

View 1 Replies View Related

C# :: Store Data In Memory After Adding Values

Oct 23, 2014

I serialize a XML file, and i have this values here:

public class ServiceConfig {
public List<DatabaseDescriptor> Databases { get; set; }
} public class DatabaseDescriptor {
[XmlElement("Name")]

[Code] ....

I have a form1 which is a datagrid view and get's updated like this:

dataGridView1.DataSource = xmlData.Databases;

Now i have a button: get tables, and it opens up form 2, there it's supposed to appear all the tables of the selected Database, when i click on the row i get the database name so i get all the list of Tables from

DatabaseDescriptor
where
DatabaseDescriptor.Name == name
(I get this when i select the row)

But then on the 2nd form, i also have 2 textbox so i add a new table, i add the tablename and id. the new value should appear in the datagridview of the tables, and when i close it and reopen it, it should be there. Maybe i should concatenate first the values or something, how do i do?

View 3 Replies View Related

C++ :: Create New Data Type To Store Big Integer?

Oct 17, 2014

i need to create a new integer data type called BigInt to store a big big integer, which includes Dint(8 bytes) and Qint(16 bytes)

here is the hint/

typedef struct BigInt {
Int data[2];
}

How can i "scanf" and "printf" them????

void ScanBigInt(const char *format, BigInt &x)
if format is “%dd” -> input Dint, if format is “%qd”--> input Qint
void PrintBigInt(const char *format, BigInt x)

View 3 Replies View Related

C++ :: Store Related Data Of Program Into External File?

May 14, 2013

How is it possible to store the related data of a program C++ into an external file (like as .txt) and retrieve it?

I want to write c++ program that can contain data members " id and phone"

like as
Code:
class profile {
private: int id,phone;
public:
void retriever() {
cout<<"Enter your ID: ";
cin>>id;
cout<<"Your Phone number is "<< phone;
};
}

avoiding formats in above class, purpose is to store data already in txt file with different id and phone numbers and it is to be retrieved by matching id number to txt file and viewing its related phone number.

View 1 Replies View Related

C :: How To Capture And Store Serial Communication Data In Buffers

Jun 18, 2013

I sent 1preample and 4bytes in transmitting side , preample contains only 1 and 0 with 4milliseconds delay, each byte contains 8bits with 2milliseconds delay , if a bit contains 1 it will send 1millisecond high and 1millisecond low signal ,and if a bit contains 0 it will send 2millisecond continuous delay, I have a problem at receiving side how to capture and store the preample and 4byte values in a buffer , i am using ARM processor it will update every 5microsecond ..

View 1 Replies View Related

C++ :: Compare Data Members Of Objects Store In Vector

Mar 6, 2014

Overview of problem : I am using std::vector to hold objects of Subject. Now this vector contains lots of objects( with lots I mean 10-20 objects at max) . These objects have string member values like category and sub_category. Both category and sub_category can have string which can be same of other objects's sub_category & category.

Issue: Now I want my std::vector to have only those objects whose's sub_category are unique. If category is not unique that's not a problem .

Secondly if we found 2 objects having same sub_category then we have to delete one of them from the vector. we will delete it based on some rules example

Rules for deleting are if

i) instance of Subject ->category = " Land " OR if category = "Jungle" then delete other duplicate object ,
ii) if above condition doesn't match then delete either of them.

I am wondering , how would I compare the sub-items from the vector . For example. I have class say Subject

class Subject {
public :
// some constructors,
// functions to get ., set category and sub category
std::String get_sub_category()
std::string get_category();
private:
std::string category;
std::string sub_category;
}

I have vector which stores object of Subjects. Example : vector<Subject> copy_vector;

Now what I want is to delete the object from vector that has same sub_category I am not looking for source code buT i need a starting point,? Example:

copy_vector[0] = Animal object that has sub_category Tiger
copy_vector [1] = Animal object with Lion as sub category
copy_vector[2] = Forest object with sub_category Tiger

What I want is to based on some conditions(which I can do ) remove either Forest or Animal object containing Tiger. But for that how would I do comparison? I have written the function and have checked it.

std::vector< Subject >copy_vector;
// copy_vector contains all the objects of Subject with redundant sub_category
for( std::vector< Subject >::iterator ii = copy_vector.begin() ; ii != copy_vector.end() ; ++ii ) {
sub_category = ii->get_sub_category();

[code] ....

View 1 Replies View Related

C++ :: Formatted TXT File And Store Data Into Their Respective Members

Apr 16, 2014

The program is supposed to read a formatted .txt file and store the data into their respective [Class] Members. It will then output the data collected onto screen.I overloaded ifstream and istream. When I call for file>>ptr[i] to read the data, something goes wrong. It prompts me to input data (which is in istream overload).The Data in .txt file is as follows;

#ifndef STUDENTTESTSCORES_H
#define STUDENTTESTSCORES_H
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

[code]....

View 6 Replies View Related

C++ :: Read Input File Of Data And Store Them In Arrays

Nov 5, 2013

Read the input file of data ( employees.txt) and store them in arrays. This company can have up to 55 employees [b]i need to do these following in these program:

Write a function to read the input file and store the data in arrays.
Write a function to calculate regular pay.
Write a function to calculate overtime pay
Write a function to calculate gross pay.
Write a function to bubble sort the employees into order by last name, first name.
Write any swap functions that are needed.
Write a function to write output to a file called payroll.txt

Format of file is EMPLOYEES.TXT[/b]

Hours Pay Rate Employee Number First Name Last name
40.0 10.00 A1234 Jane Adams
50.0 10.00 L8765 Mary Lincoln
25.5 10.85 W7654 Martha Washington
52.0 15.75 A9876 John Adams
45.0 25.00 W1235 George Washington
40.25 55.00 L9087 Abraham Lincoln
30.0 9.75 T9876 William Tell
42.5 12.50 M7654 Missy Muffett
30.0 10.00 P8765 Peter Piper

HERE IS MY CODE SO FAR:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void tellUser();

[code]....

View 9 Replies View Related

C++ :: Structure To Store Data From Database - Dynamic Initialization Of Variable

Jan 5, 2013

I created a class (let call it X) which contains the structure to store the data from my data base. Them I have a class (call Y) which will contain a list for each row in my data base. Third, I have a class with thousands variables (Z). What I am trying to do is to take the list of objects (Y) that contains the data to initialize Z. What I want to now if I can do something like that.

Imaging that one of my rows contain the following data:
Type Nameofvariable etc...
"static const double; MNFAIL ; 0; 0; 0,25"

In my list I have a node with contain this data

I want to use the field Nameofvariable to initialize the variable called MNFAIL contained in my class Z.

Is it possible in C++

View 3 Replies View Related

C++ :: Float And Double Data Types - Cannot Store Infinite Numbers

Sep 6, 2013

I was working on float and double data types and to see the results i wrote this program:

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main() {
ofstream outputF("output.txt");
double a = 1;
double outcome;

[Code] ....

Well I understand the part it cannot store infinite numbers. but if you take a look at the output for example (since it is too long i just added some of the outputs)

//---------------------
for the value of : 001
1
//---------------------
for the value of : 002
0.5
//---------------------
for the value of : 003
0.3333333333333333148

[Code] ....

if you look carefully at the value "5" and "10" results. it is awkwardly abnormal. which is something i couldnt understand. also it is the same with value "20", "25", "40", "50" and so on.

View 5 Replies View Related

C++ :: Use Circular Linked List And Data Structures To Store Tasks

Mar 30, 2014

The program use a circular linked list and data structures to store the tasks.

- Every task should include a task name, a name for the person assigned to it, and the deadline for the task.
- Variables should be dynamic and their sizes should be determined at runtime based on the length of user input.
- You should implement the following functions (with appropriate arguments and return types) for your structure: add(), remove(), search(), and list().
- The add()function should add tasks alphabetically by task name. You do not need to implement any file operations.
- The search() function should be able search for a task by the task assignee name or the task name.
- The list() function should print records to the screen in the order they appear in the circular linked list.
- You should successfully deallocate all of the allocated memory before termination of your program.

View 4 Replies View Related

C++ :: Writing Functor - Read Data From A File And Store In Multimap

Mar 29, 2014

How would i write a functor for this code. The code is written to read data from a file and store in a multimap.

The data has numbered lines. E.g.:
1 This is a string
2 This is a string too

So the aim is to store each word in the line with the number and then to enter a word to search for the line numbers it appears on. I do not know how to go about and write a functor

#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<map>
using namespace std;
int main() {
multimap<int, string>myMap;

[Code] ....

View 4 Replies View Related

C++ :: Read Data From A File Then Store / Search And Display Using Classes And Arrays

Apr 12, 2013

A company uses two text files: one to store employees' details and another to log their sign in/out time.

The details file - called details.txt" has the following format: ID, Name, Date of Birth, SSN, Department, Position - separated by spaces.

An extract from the file looks like this:

10 alice 4/23/1972 123-45-6789 support assistant
3 bob 6/7/1980 111-12-1134 logistics manager
1 carol 10/2/1963 987-123-1143 admin ceo
2 dave 10/3/1974 902-22-8914 admin cfo
17 erin 6/13/1991 126-83-1942 technology supervisor
15 frank 2/22/1987 303-12-1122 logistics assistant

"timelog.txt" contains daily logs of when employees arrive and leave. It has the following format: ID, Date, Arrival Time, Departure Time - separated by spaces. An extract from the file looks like this:

10 2/11 0900 1700
3 2/11 0930 1730
1 2/11 1100 2000
2 2/11 1000 1530
17 2/11 0900 1700
10 2/12 1000 1830
3 2/12 0930 1730
1 2/12 1100 1900
2 2/12 1030 2000
17 2/12 0900 1700
15 2/12 1100 1600

I have to write a program that searches for specific records using some search parameter, and displays them. Ok first i have to read the data from the files and store them. this is what i have so far....

#include <iostream> //Accesses libaries for console input and output
#include <fstream> //Needed to access the fstream object to read files
#include <string> //Needed to access the string class
#include <cstdlib>

[Code] ....

I know my class and array code is totally wrong i dont know how to store the data for the info is in integer and string form... do i use strings, arrays?

View 1 Replies View Related

C++ :: Capture Incoming Serial Data And Store It Into Array For Controlling Functions

Mar 22, 2014

How to capture incoming serial data and store it into an array for controlling functions. But I am now working with a radio module that receives incoming data and stores it into a uint_8t.

From there in the basic sketch that the radio library came with it is printed in the serial terminal like this:

uint8_t buf[RF22_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf22.waitAvailableTimeout(500)) {
// Should be a message for us now
if (rf22.recv(buf, &len)) {
Serial.print("got reply: ");
Serial.println((char*)buf);

I have read a lot of tutorials on pointers, and I am just having a very hard time grasping how to extract data out of one. I realize this is char and not integers. The goal is to transmit five integers in a digital state of either 1 or 0, and then store them in the receiving side and control 5 outputs based on the status of those 5 bits. This is proving to be quite confusing for me though as I cannot seem to grasp how to control the pointer logic.

View 1 Replies View Related

C :: Program That Can Implement Functions That Store / Get And Deletes Text / Binary Data To Given Memory Area

Sep 19, 2013

I got an assignment at school asking for a program that can implement functions that store, get and deletes text/binary data to a given memory area. We are supposed to make kind of like a tiny-mini OS..any links to some tutorials or explanations hon ow to understand this and be able to make a program like this on my own?

View 9 Replies View Related







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