I am having a little trouble with my class Person program. It runs and builds without error...Yay....except I am getting 0 output. Anyone have any advice?
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
class Person{
private:
string name;
int age;
public:
Person (string n, int a); //n=name, a=age
string get_name() const;
int get_age() const;
void increment_age();
void print()const;
};
Person::Person (string n, int a){
name = n;
age = a;
}
string Person::get_name() const{
return name;
}
void Person:: increment_age(){
age +=1;
}
void Person::print() const{
cout << name << endl;
cout << age << endl;
}
class Car{
private:
string model;
Person *owner;
Person *driver;
public:
Car (string m);
void set_driver (Person* p);
void set_owner (Person* p);
void print() const;
};
Car::Car (string m){
model = m;
}
void Car:: set_driver (Person* p){
driver = p;
}
void Car:: set_owner (Person* p){
owner = p;
}
void Car::print() const{
cout << model << endl;
cout << driver->get_name() << endl;
cout << owner->get_name() << endl;
}
int main(){
vector<Person*> people;
const int PERSON_SZ = 3;
char * names[] = { "Todd", "Melissa" "Ashley" };
int ages[] = { 43, 33, 22 };
for ( int i = 0; i<PERSON_SZ; i++){
Person *a = new Person ( names[i], ages[i]);
people.push_back(a);
}
vector<Car*> cars;
const int CAR_SZ =3;
char * models[] = { "Suburban", "Ford Explorer", "Honda" };
for ( int i=0; i<CAR_SZ; i++){
Car *c = new Car (models[i]);
c-> set_driver ( people[rand()% (people.size())] );
c->set_owner ( people [rand()% (people.size()) ] );
cars.push_back(c);
for (int i=0; i<CAR_SZ; i++){
std::vector<Car*> print();
}
return 0;
}
}