Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C++ Help with vectors of class
New Posts  All Forums:Forum Nav:

C++ Help with vectors of class - Page 2

post #11 of 17
Thread Starter 
Quote:
Originally Posted by Coma View Post

Well, why would you want to? I don't think your teacher will complain if it can hold more than 100, but you can always just hide that fact from the user, preventing them from adding more.

It isn't that I would want to limit it, but the teacher is using a test file that "may contain up to 100 entries" And I don't know if that means he wants it limited to 100, or at a minimum has to be able to take 100. I am kinda scar'ed from my last year teacher where he would grade on stuff that he didn't say, I think its because he hated me though.
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
post #12 of 17
Just have a counter with the number of entries that are currently stored. If the user wishes to add another and the counter is at 100, then don't add it and just cout an error message.

My professor made us create data structures from scratch to understand them better, so my solution to your problem would be a linked list. I'm guessing a vector uses some form of a linked list. thumb.gif
Current
(12 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Z68 Extreme4 Gen3 EVGA GTX 570 Classified 4x4GB Corsair XMS3 
Hard DriveCoolingPowerCase
Samsung 830 Thermaltake Frio OCZ ZS 850W Lian Li Lancool First Knight K9 
MouseAudioOtherOther
Logitech G500 Audinst HUD-MX1 Sennheiser HD598 Swan D1080MkII 
  hide details  
Reply
Current
(12 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k ASRock Z68 Extreme4 Gen3 EVGA GTX 570 Classified 4x4GB Corsair XMS3 
Hard DriveCoolingPowerCase
Samsung 830 Thermaltake Frio OCZ ZS 850W Lian Li Lancool First Knight K9 
MouseAudioOtherOther
Logitech G500 Audinst HUD-MX1 Sennheiser HD598 Swan D1080MkII 
  hide details  
Reply
post #13 of 17
Thread Starter 
Alright I need help again, I am trying to to pass it to my class with a vector now, and am very confused.

here is my class:
Code:
//EmployeeInfo

#include <string>
using namespace std;

class EmployeeInfo
{
public:
        EmployeeInfo();

        void setEmployeeLName(string lName);
        void setEmployeeFName(string fName);
        void setEmployeeMSal(double monthlySal);
        
        string getEmployeeLName() const;
        string getEmployeeFName() const;
        double getEmployeeMSal()  const;
        
        void displayEmployeeInfo() const;

private:
        string lastName_;
        string firstName_;
        double monthlySal_;
};

here is my problem, I know how to pass an array element to a function. but how do I pass it with a vector? I know i can use [ i ] but if I do that then if I am correct the vector doesn't do a range check. But if I use push_back it will add elements as needed.

so if I am trying to assign a value to say
Code:
myvector[3]
how would I use that with my class so that it will always add the element to the next spot?
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
post #14 of 17
Thread Starter 
Bump, some one please explain ^^^^^^^ previous post to me
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
post #15 of 17
Ok if I am following correctly the way I handled this in a simple way was to load all the objects at once into a vector of my object. I just called the load function everytime I was in a different branch of the file and just deleted it on the way out.

if you need the value of a certain item you could always ask y=vector.at(x) then it would give you the value in y and pass y along. But I dont think im solving your problem lol
    
CPUMotherboardGraphicsRAM
Intel Core i7 930 [4.33 Ghz] EVGA X58 SLI LE EVGA GTS 450 [SLI] 6 GB DDR 3 OCZ 1600 [1T-7-8-7-18 @ 1474] 
Hard DriveOptical DriveOSMonitor
Vertex 2 [120 GB] + 4x WD Green 2 TB [Raid1] Samsung BD-R [12x] Microsoft Windows 7 Pro [x64] [3] Samsung SyncMaster 2233sw 
KeyboardPowerCaseMouse
I-rocks Corsair HX650 [650W] Lian Li PC K62 Logi 
Mouse Pad
Metallica 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel Core i7 930 [4.33 Ghz] EVGA X58 SLI LE EVGA GTS 450 [SLI] 6 GB DDR 3 OCZ 1600 [1T-7-8-7-18 @ 1474] 
Hard DriveOptical DriveOSMonitor
Vertex 2 [120 GB] + 4x WD Green 2 TB [Raid1] Samsung BD-R [12x] Microsoft Windows 7 Pro [x64] [3] Samsung SyncMaster 2233sw 
KeyboardPowerCaseMouse
I-rocks Corsair HX650 [650W] Lian Li PC K62 Logi 
Mouse Pad
Metallica 
  hide details  
Reply
post #16 of 17
Thread Starter 
Quote:
Originally Posted by sdla4ever View Post

Ok if I am following correctly the way I handled this in a simple way was to load all the objects at once into a vector of my object. I just called the load function everytime I was in a different branch of the file and just deleted it on the way out.
if you need the value of a certain item you could always ask y=vector.at(x) then it would give you the value in y and pass y along. But I dont think im solving your problem lol

not following at all?
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
post #17 of 17
Thread Starter 
Read second part of first post for code to help me please
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
2600K Sandy Bridge 5+Ghz ASUS P8P67 DELUXE x2 EVGA GTX 580 Water Cooled in SLI G.SKILL Ripjaws X Series 16GB 1600 
OSMonitorPowerCase
Duel Boot, Win 7 & Unbuntu 2 x 24in monitors Plus a 1080p projector CORSAIR Professional Series Corsair 600T 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C++ Help with vectors of class