473,385 Members | 1,282 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.

Help with vectors

Ok, below I have taken parts of the program that I know can be fixed but I don't know how to do it. Is there a way to have the arrival to be one whole vector? or do I have to split it up like i did. It reads HH:MM.

vector<short> arrival_h(20), arrival_m(20), depart_m(20), depart_h(20);
vector<string> list_names;


cin >> hour >> temp >> min;

arrival_h[worker_num - 1] = hour;
arrival_m[worker_num - 1] = min;

cin >> hour >> temp >> min;

depart_h[worker_num - 1] = hour;
depart_m[worker_num - 1] = min;


for ( short l = 0; l < list_names.size(); l++)
{
servd_h = depart_h[l] - arrival_h[l];
servd_m = depart_m[l] - arrival_m[l];

cout << '\n' + list_names[l] + ": ";
cout << arrival_h[l] << ':' << arrival_m[l];
cout << " " << depart_h[l] << ':' << depart_m[l];
cout << " " << servd_h << ':' << servd_m;

}
Dec 13 '07 #1
1 916
weaknessforcats
9,208 Expert Mod 8TB
You might consider a class to contain your data:
Expand|Select|Wrap|Line Numbers
  1. class Time
  2. {
  3.      private:
  4.         unsigned short HH;
  5.         unisgned short MM;
  6.      public:
  7.          //TODO: methods as needed
  8. };
  9.  
Then you could have a vector<Time>. You would write Time methods to accesss the hour and minute and an operator<< could supply the colon on the display.

Doing it this way hides the fact that you are using unsigned shorts for your implementation. Later, if you need to redesign this class to, say, use a string to hold the data, then you will not need to change any of the code that uses the Time class. Your redesign would be limited to the Time methods.
Dec 13 '07 #2

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

Similar topics

5
by: Pratyush | last post by:
Hi, Suppose there is a vector of objects of class A, i.e., std::vector<A> vec_A(N); The class A satisifies all the STL vector requirements. Now I wish to add some attributes for each of the...
5
by: Computer Whizz | last post by:
I was reading through Accelerated C++ at work when I read through the first mention of Vectors, giving us certain functions etc. Is there any benefit of Arrays over Vectors? Since all Vectors...
3
by: Amit | last post by:
Hello. I am having some problem organizing a set of vectors. The vectors itself, could contain a pointer( say integer pointer) or could contain another object MyClass. 1>So, first of all, is...
4
by: Dr. J.K. Becker | last post by:
Hi all, I have vectors that holds pointers to other vectors, like so: vector<whatever> x; vector<whatever*> z; z=&x; Now I add something to x
13
by: Ben | last post by:
I have a program which is using a lot of memory. At the moment I store a lot of pointers to objects in std::vector. (millions of them) I have three questions: 1) Lets say the average Vector...
4
by: Brian Basquille | last post by:
Hello all, Well, we've gotten to it: the real meaty area of my Air Hockey game.. Any help or suggestions for the following would be much appreciated. In plain terms: My paddle needs to be...
11
by: natman | last post by:
Hi i need to write a funcition called install, its takes as arguments 1- a vector 2-a number 3-a list called next_level so heres where it get kinda weird: next_level is a list comprising of...
5
by: madhu | last post by:
http://msdn2.microsoft.com/en-us/library/fs5a18ce(VS.80).aspx vector <intv1; v1.push_back( 10 ); //adds 10 to the tail v1.push_back( 20 ); //adds 20 to the tail cout << "The size of v1 is " <<...
2
by: Thelma Lubkin | last post by:
I use my own matrix and vector classes. I wrote them before such things were generally available and I've stuck with them ever since. I've just added an Octonion class derived from the vectors...
1
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
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
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:
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.