473,377 Members | 1,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 software developers and data experts.

Overloading '<<' operator

3
Can any one help me in that:
I wont to write an OO-based program that will make use of two classes in creating
composed objects.
The first class is the Customer class that is to contain the following:
• Function to print the customer’s data.
• Function to calculate the total cost for the customer.
• Objects made of this class will contain a
o Customer name
o Customer phone number and
o Array of three pointers to objects of type Call.
• Use a friend functions bubble-sort to sort data by cost.
• Use a static data member to keep track of the total revenues based
on all customers. The accumulated cost of all the customers will be
the total revenues made by the company.
The other class is the Call class to represent the data for one call. It is to
contain the following:
• Overload the "<<" to print the objects of type Call.
• Three data elements
o Country
o Number called and
o Cost of call.
You may add other functions to the above classes as you see fit. Use
gets and set conventions. Include proper constructors and
destructors.
The program is to:
1. Received three strings as input. Each string contains one
customer’s data in the following format (see example at end):
“Customer-name his-number country called number cost country
called number cost country called number cost”.
a. You may assume three customers, one call per country and
three calls per customer.
b. Use the input data and output format provided at the end of
the assignment for the final run.
2. Calculate and print total cost of the calls for each customer.
3. Calculate and print the total revenues from all the customers.
4. Print the calls of each customer sorted by cost in ascending order.
5. Use Dynamic allocation /de-allocation of memory where possible.
Mar 26 '07 #1
6 1564
sicarie
4,677 Expert Mod 4TB
Welcome to theScripts, here are our Posting Guidelines:

Posting Homework or Coursework Questions and Answers
This site is not a place where you can get your homework and course work done for you. Ignoring the questionable morals of getting someone else to do your work towards a formal qualification you will learn a lot more by attempting the problem yourself, then asking for help with the bits that are not working. You will be more likely to get help if you appear to have made an attempt at the problem yourself.

* If it appears that the question has just been pasted directly from a text book or coursework assignment our moderators have been instructed to meet this with a set response. This is a pre-written message asking you to make some attempt at the assignment yourself before asking questions about specific problems and referring you to this FAQ.
* Do NOT post your complete source code. Remember, you found this site, so can your professors and tutors and they are likely to take a dim view if you hand in something that appears to be copied from this site. In most academic institutes the minimum response to copying of assignments is a 0 mark for the assignment in question. If you post your entire code your professor will not know it was your work, you may be penalised for copying from yourself.
* If an expert requests that you provide more of your code then you can PM it to them, however please do not PM them your code unless requested.
* Acceptable questions that students can ask are on functionality and theory or syntax corrections in small posted code snippets.
* Please make sure you have asked an actual question worded in English outside of the text of your assignment that you have posted.
With that in mind, what's your specific question, and what have you already tried?
Mar 26 '07 #2
koko
3
I wanna know just how yo
Overload the "<<"
to use it as cout
Mar 26 '07 #3
sicarie
4,677 Expert Mod 4TB
I wanna know just how yo
Overload the "<<"
to use it as cout
Check this out, and see if it helps.

By the way, that was found on the first page of returns for a google search of "c++ overload <<".

(I have modified the title to better describe the issue)
Mar 26 '07 #4
koko
3
thank u sicarie
I tried that one but still not sure
is there any other way
i mean they r using ostream insted of the class name
????????
why?
Mar 27 '07 #5
sicarie
4,677 Expert Mod 4TB
thank u sicarie
I tried that one but still not sure
is there any other way
i mean they r using ostream insted of the class name
????????
why?
I don't have a computer in front of me, and won't for a few hours yet, but did you try running that google search and looking as those responses? Those can help you get an idea of the different ways it can be done, and the things that are necessary.
Mar 27 '07 #6
horace1
1,510 Expert 1GB
have a look at this simple example of an Impedance class
Expand|Select|Wrap|Line Numbers
  1. class impedance {                                // impadance class
  2.       complex<float> z;
  3.       public:
  4.       // constructor with  real and imaginary parameters 
  5.       impedance(const float r, const float i) { z = complex<float>(r, i); }  
  6.       // copy constructor    
  7.       impedance(const impedance &zin) { z = zin.z; }   
  8.       // overloaded assignment operator   
  9.       impedance &operator=(const complex<float> zin) { z=zin; return *this; }
  10.        // overloaded << operator 
  11.       friend ostream &operator<<( ostream &stream, const impedance &z)
  12.          { stream << z.z; }      
  13. };
  14.  
Mar 27 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: pmatos | last post by:
Hi all, I have the following code: class test { public: test(const std::string *n) : name(n) {} virtual ~test() {} const std::string * getName() { return name; }
3
by: Suresh Tri | last post by:
Hi all, I was trying to overload '<' operator for (varchar,varchar). But in the function which handles the comparision I want to use the previous '<' operator.. but it is going into a recursion....
6
by: n2xssvv g02gfr12930 | last post by:
Does anyone know of an example of overloading operator ->* Cheers JB
1
by: atomik.fungus | last post by:
Hi, as many others im making my own matrix class, but the compiler is giving me a lot of errors related to the friend functions which overload >> and <<.I've looked around and no one seems to get...
3
by: md | last post by:
Hi, the following code is working for static objects. ie the statement IntArray x(20); my problem is i want to use this overloading operator for dynamically created objects...
2
by: nayannovellus | last post by:
As we know that both copy constructors and overloading = opeartor copies one object to another then whats the difference between copy constructor and overloading = operator. There must be some...
3
by: Aff | last post by:
hi, i wold like to ask, why is it when overloading operator we send int value is there any way around?. e.g. class abc { protected: int *a; private: int operator(int );
6
by: Peter v. N. | last post by:
Hi all, Maybe this has been asked a million times before. In that case I'm sorry for being to lazy to search the Internet or look it up in a decent C++ reference: I read in O'Reilly's C++...
11
by: dascandy | last post by:
Hello, I was wondering, why is overloading operator. (period) forbidden? It would make a few odd applications possible (dynamic inheritance and transparent remote method invocation spring to my...
0
by: citystud | last post by:
I am trying to convert the c++ code to C#, but find difficulty to convert the overloading operator. Here is the source code. I don't really know how to implement the operator = and operator () in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
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...
0
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.