this is what i have so far: - #include <iostream>
-
#include <string>
-
#include <vector>
-
#include <fstream>
-
-
using namespace std;
-
-
class Person
-
{
-
protected: string o_name;
-
-
public:
-
Person(string name)
-
{
-
this->o_name = name;
-
}
-
bool operator==(const Person& obj) const;
-
bool operator!=(const Person& obj) const;
-
};
-
-
bool Person::operator ==(const Person& obj) const
-
{
-
return (obj.o_name == this->o_name);
-
}
-
bool Person::operator !=(const Person &obj) const
-
{
-
return (obj.o_name != this->o_name);
-
}
-
-
-
class Worker: public Person
-
{
-
friend ostream& operator<<(ostream&, const Worker &);
-
friend istream& operator>>(istream&, Worker &);
-
-
private:
-
string workPlace;
-
int age;
-
public:
-
Worker(string name, string w_wP, int w_a): Person(name)
-
{
-
workPlace = w_wP;
-
age = w_a;
-
}
-
string getName() const;
-
string getWorkPlace() const;
-
int getAge() const;
-
void print() const;
-
};
-
string Worker::getName() const
-
{
-
return o_name;
-
}
-
string Worker::getWorkPlace() const
-
{
-
return workPlace;
-
}
-
int Worker::getAge() const
-
{
-
return age;
-
}
-
void Worker::print() const
-
{
-
cout << "Name = " << o_name
-
<< "; WorkPlace = " << workPlace
-
<< "; Age = " << age;
-
}
-
ostream& operator<<(ostream& osObject, const Worker& worker)
-
{
-
osObject <<"Name = " << worker.o_name << "; Work Place = " << worker.workPlace << "; Age = " << worker.age;
-
return osObject;
-
}
-
istream& operator>>(istream& isObject, Worker& worker)
-
{
-
isObject >> worker.o_name >> worker.workPlace >> worker.age;
-
return isObject;
-
}
-
-
-
int main()
-
{
-
string w_name, w_name2;
-
string w_workPlace, w_workPlace2;
-
int w_age, w_age2;
-
char ch;
-
-
cout << "Enter name, work place and age, comma seperated : ";
-
getline(cin, w_name, ',');
-
getline(cin, w_workPlace, ',');
-
cin >> w_age;
-
-
cin.get(ch);
-
-
cout << "Enter name, work place and age, comma seperated : ";
-
getline(cin, w_name2, ',');
-
getline(cin, w_workPlace2, ',');
-
cin >> w_age2;
-
-
cin.get(ch);
-
-
-
Worker w1(w_name, w_workPlace, w_age);
-
Worker w2(w_name2, w_workPlace2, w_age2);
-
-
if(w1 == w2)
-
{
-
cout << "They have the same name" << endl;
-
}
-
else if(w1 != w2)
-
{
-
cout << "They do not have the same name" << endl;
-
}
The problem i have is how do i read a text file that has comma deliminated values in it and then store the information in a worker object. ANy help greatly appreicated
1 2453
like if the file had the values:
mark,xwork,34
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rakesh Sinha |
last post by:
I have a very trivial question. But I searched in google / archives of
this group to get the answer, checked the C++ FAQ - but did not
precisely what I was looking for.
The problem is with...
|
by: John B. Lorenz |
last post by:
I'm attempting to write an input routine that reads from a comma delimited
file. I need to read in one record at a time, assign each field to a field
array and then continue with my normal...
|
by: Gary Smith |
last post by:
Hi, I've got a field that contains a list of rooms.
In most cases, this contains a single ID. However, under some
circumstances, the field may contain a list of two IDs which
are broken by a...
|
by: Hilary Cotter |
last post by:
Thanks for all the help you gave me yesterday.
here is another question.
I have a comma delimited file called redirect.txt which looks like
this
test, /test.htm
test 123,/test123.htm
|
by: pesso |
last post by:
I have a string that contains the following:
string s = "130,41,43,178,41,17,6,78,244,35,202,144,115";
They are comma separated byte numbers, and I need to
initialize my byte array with them....
|
by: ungvichian |
last post by:
So, right now I'm writing a program in VC++.Net with MFC, and one of
the steps involves reading numeric values from a comma delimited file
(like 4.56, 2.44, 3.453 etc.). The only methods I've been...
|
by: Avi |
last post by:
I need to create a text file that has the data from the 10 tables in
the database. The number of fields in the tables exceeds 255 and so I
cannot make a new table with all the fields and then...
|
by: pedroalves |
last post by:
Hi all,
This is not a question about how to #define COMMA ,
Please keep reading.
Recently in binutils, we introduced a macro like this:
#define STRING_COMMA_LEN(STR) \
(STR), ((STR) ?...
|
by: aarklon |
last post by:
Hi all,
why does C language permits an extra comma in initializer list
ex:- int days = {
31,28.31,30,31,30,
31,31,30,31,30,31,
}
i have heard it is for the purpose of automatic code...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |