473,385 Members | 1,461 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,385 software developers and data experts.

counting objects

I have everything figured out but this one little detail could you help me into figuring out how to count each car and adding them to the fleet. I need to know the syntax and what type of mehtod I need to use. The part I'm having trouble with is marked//////starting here!!!!!!!!!!!.Do I use count or an overloaded operator function, please help me. Of course this is just a segment of my code it is longer than this. I hope it is sufficient enough for you to understand my problem I appreciate your help in advance.

Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.     Fleet f1;
  3.     Vehicle v1,v2,v3("GMC", "Yukon", "2007", "rented");
  4.     v1.set("Buick", "Lucerne", "2006", "shop");
  5.     v2.setMake("Ford");
  6.     v2.setModel("Mustang");
  7.     v2.setYear("1967");
  8.     v2.setStatus("available");
  9.     Vehicle v4(v2);
  10.     cout << v4.getMake() << " " << v4.getModel() << " " <<  v4.getYear() << " " << v4.getStatus()<< endl; 
  11.     Vehicle v5;
  12.     cin >> v5;
  13.     cout << v1 << v2 << v3 << v4 << v5;
  14.     /*f1 + v1; // adds a vehicle to the fleet f1/////////////starting here!!!!!!!!!!!!!!!!!!!!!!
  15.     cout << f1;
  16.     f1 + v2; f1 + v3; f1 + v4; f1 + v5; 
  17.     cout << f1;
  18.     cout << "Vehicles in Fleet: " << f1.getTotal() << endl;
  19.     cout << "Vehicles available: " << f1.getAvailable() << endl;
  20.     cout << "Vehicles rented: " << f1.getRented() << endl;
  21.     cout << "Vehicles in shop: " << f1.getShop() << endl;*/
  22.     return 0;
  23. }
Feb 7 '07 #1
2 969
Ganon11
3,652 Expert 2GB
You will have to add a function to your Fleet class called add(Vehicle) in order to add vehicles to the fleet. The Fleet will probably store the Vehicles in a List or Vector, or some other container.

We could probably help you more if you post the Fleet class - at least the relevant sections of the code.
Feb 7 '07 #2
You will have to add a function to your Fleet class called add(Vehicle) in order to add vehicles to the fleet. The Fleet will probably store the Vehicles in a List or Vector, or some other container.

We could probably help you more if you post the Fleet class - at least the relevant sections of the code.


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include "vehicle.h"
  5. #ifndef FLEET
  6. #define FLEET
  7. using namespace std;
  8.  
  9. class Fleet{
  10.     Vehicle vehicle;
  11. private:
  12. string available, rented, shop;
  13. int total;
  14.  
  15. public:
  16. Fleet();
  17. Fleet(int,string, string,string);
  18. Fleet(const Fleet&);//, string);
  19. void setTotal(int);
  20. void setAvailable(string);
  21. void setRented(string);
  22. void setShop(string);
  23.  
  24.  
  25. int getTotal()const;
  26. string getAvailable()const;
  27. string getRented()const;
  28. string getShop()const;
  29.  
  30.  
  31.  
  32. //void Fleet::print()const;
  33. //void Fleet::read();
  34.  
  35. //Fleet& operator++();
  36. //Fleet operator+(const Fleet& f) const;
  37. //bool operator> (const Fleet& f) const;
  38.  
  39.  
  40. friend ostream& operator<<(ostream& os, const Fleet&);
  41. friend istream& operator>>(istream& is, Fleet&);
  42. };
  43.  
  44. #endif
Feb 8 '07 #3

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

Similar topics

6
by: Elbert Lev | last post by:
Please correct me if I'm wrong. Python (as I understand) uses reference counting to determine when to delete the object. As soon as the object goes out of the scope it is deleted. Python does...
1
by: ash | last post by:
hi does anyone has any experience with flyweight pattern with refernce counting i want to share objects between multiple clients and want to delete the object from shared pool when the last...
1
by: stephan beal | last post by:
Good morning, C++ers, A couple days ago i came across a useful trick for counting instances of a given class, and i thought i'd pass it on: Conventionally, as described in several books, to do...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
1
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don't understand completely. It says "A garbarage...
3
by: Ole Nielsby | last post by:
I need to implement reference counting in a class hierarch, in a thread safe manner. (The classes are umanaged but I might want to compile them with the /clr option.) Some of the objects - atoms...
14
by: Dan | last post by:
Is this discouraged?: for line in open(filename): <do something with line> That is, should I do this instead?: fileptr = open(filename) for line in fileptr: <do something with line>
1
by: oec.deepak | last post by:
Hi Cn any one telll me what is Reference counting in C++.
8
by: mdoxdo | last post by:
Hi all, I was wondering if there is a way to get the number of references an objects have (ie, other objects reference that object)? I know that .Net GC uses a different mechanism than the...
5
by: Stefan Istrate | last post by:
Hello, I have a class A and I want to know at every moment what is the number of objects of type A. I know that a good solution for this is to add a static variable (member of class A) and...
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
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.