I have been told it is good to overload the stream extraction operator to load data from a file. Would I simple use this in my class: friend ifstream &operator>>( ifstream &input, Class &C ) { input >> C.variable1 >> C.variable2 >> C.variable3; return input; } What are the advantages of overloading the stream extraction operator to read data from a file? Also I am confused what to do in main. At the moment to read in the data I have for example: ifstream fin; fin.open("filename.txt"); if(fin.good()) { object1 = new Class[10]; for (int i=0; i<10; i++) { fin >> …

Member Avatar
Member Avatar
+0 forum 7

I would like to convert a procedural database program that I have created to an object oriented program. In my procedural program I use a struct: struct shoes{ char Name[20]; int Number; double ShoeSize; }; Putting this into a class would I simply use: class Shoes{ public: //Function declerations private: chat Name[20] int Number; double ShoeSize; }; Originally I passed the struct between functions, for example: void view(Shoes *Shoe); Can I do the same with the class? would this pass all the variables or would I have to separetly pass each variable? if not what is the best way to …

Member Avatar
Member Avatar
+0 forum 40

I have created a basic object oriented database of a list of shoes containing the shoe name, number and shoe size. I am trying to sort the list of shoes alphabetially by name and by shoe size. I have the following code: Shoes.h: #include <iostream> #include <fstream> #include <string> #ifndef Shoes_Shoes_h #define Shoes_Shoes_h using namespace std; class Shoe { public: //Constructors Shoe(); Shoe(string Name_, double ShoeSize_, int Number_); //Destructor ~Shoe(); //Getters string getName() const; double getShoeSize() const; int getNumber() const; //Setters void setName(const string Name_); void setShoeSize(const double ShoeSize_); void setNumber(const int Number_); //Variables string Name; double ShoeSize; int Number; …

Member Avatar
Member Avatar
+0 forum 13

How would I pass an element in a struct array. I have to call the function: new(Shoe[num], num); where num is the number of elements in the database. I have declared the function as: void new(Shoes Shoe[], num); but I get the error: cannot convert 'Shoes' to '*Shoes' for argument '1' to 'void new(Shoes*, num int&)'

Member Avatar
Member Avatar
+0 forum 10

**What I would like to do:** - Read data from text file - Display data from text file - Add new data to text file - Save new data to text file **The file format used is as follows:** Number of items in text file (3) Name 1 Number 1 Date 1 Name 2 Number 2 Date 2 Name 3 Number 3 Date 3 etc..... **The code I have:** struct Shoes { char Name[20]; unsigned int Number; double Size; }; int Main() { //Load file into struct//////////////////////////// fstream input_file; // open the file input_file.open(FILENAME); Shoes Shoe[MAX]; int i = 0; …

Member Avatar
Member Avatar
+0 forum 12

I have to create a database with the data stored in a .txt file. Each record is for a company with the following fields: Name, Place, East(km), North(km). Each record from the file needs to be read into a struct array. I have managed to read the records into a struct array but I need to create several other functions: Add_Company() - To add a company to the struct array Read_Companies() - Read each company record by calling the function Add_Company List_Distance() - Distance Between two specified companies Delete_Company() - Deletes a company record A user menu would be needed …

Member Avatar
Member Avatar
+0 forum 55

I have to create a database with the data stored in a .txt file. Each record is for a company with the following fields: Name, Place, East(km), North(km). Each record from the file needs to be read into a struct array. I have managed to read the records into a struct array but I need to create several other functions: Add_Company() - To add a company to the struct array Read_Companies() - Read each company record by calling the function Add_Company List_Distance() - Distance Between two specified companies Delete_Company() - Deletes a company record A user menu would be needed …

Member Avatar
Member Avatar
+0 forum 9

The End.