CJK 13
New Member
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 2475 CJK 13
New Member
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 respect to reading 'long double's from a stream
separated by
comma.
#include <iostream>
|
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 processing. I am having no luck at
all finding different routines written in C to read delimited files of any
kind. I have a few ideas of how I might go about this but I bet I'm
re-inventing the wheel and there already exists some efficient code out...
|
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 comma.
For example: BENL LT, RAT LT
At the moment, I've got the VBA bits working on the single
ID stuff, but, should it come across a list like the above,
|
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. Looks like I need a loop
or something. What would be the best way to take a
comma separated string to initialize a byte array using cs?
| |
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 able to find
to read the values all involve StreamReader, and I can't figure out how
to use this. Since I'm using MFC, I'm using CFile instead.
Also, none of the methods seem to come with a method for error
catching. I want my program to be...
|
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 export it into a
text file.
Is there any s/w out there I could use? I am not much of a programmer
but I heard I could use VBA to get this done. Any help with the code
will be appreciated.
Thanks
|
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) ? sizeof (STR) - 1 : 0)
|
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 generation
is there any other purpose than this, if so why ...????
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |