Last active
April 6, 2016 17:37
-
-
Save lennysh/20b3d2e21697281caa3767dfc5a08bdb to your computer and use it in GitHub Desktop.
Vehicles Class (C++)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> // will be used | |
using namespace std; | |
#define SIZE 3 // Number of Vehicles to store | |
class Vehicles{ | |
private: | |
string vBrand[SIZE]; | |
string vModel[SIZE]; | |
int vYearMan[SIZE]; | |
public: | |
void setBrand(string, int); | |
void setModel(string, int); | |
void setYearMan(int, int); | |
string * getBrand(); | |
string * getModel(); | |
int * getYearMan(); | |
void getVInfo(); | |
void printVInfo(); | |
}; | |
void Vehicles::setBrand(string b, int i) { | |
*(vBrand + i) = b; | |
} | |
void Vehicles::setModel(string m, int i) { | |
*(vModel + i) = m; | |
} | |
void Vehicles::setYearMan(int ym, int i) { | |
*(vYearMan + i) = ym; | |
} | |
string * Vehicles::getBrand() { | |
return vBrand; | |
} | |
string * Vehicles::getModel() { | |
return vModel; | |
} | |
int * Vehicles::getYearMan() { | |
return vYearMan; | |
} | |
Vehicles g; | |
void Vehicles::getVInfo() { | |
for(unsigned int i = 0; i < SIZE; i++) { | |
string vb, vm; | |
int vym; | |
cout << "Enter Vehicle Brand " << "[" << i + 1 << "/" << SIZE << "]: "; | |
getline(cin, vb); | |
cout << "Enter " << vb << "'s Model " << "[" << i + 1 << "/" << SIZE << "]: "; | |
getline(cin, vm); | |
cout << "Enter the Year Manufactured " << "[" << i + 1 << "/" << SIZE << "]: "; | |
cin >> vym; | |
g.setBrand(vb, i); | |
g.setModel(vm, i); | |
g.setYearMan(vym, i); | |
cin.ignore(); | |
} | |
} | |
void Vehicles::printVInfo() { | |
string *b_ptr, *m_ptr; | |
int *ym_ptr; | |
string header = "\t\t\tVEHICLES INFO"; | |
string space = "\t"; | |
b_ptr = g.getBrand(); | |
m_ptr = g.getModel(); | |
ym_ptr = g.getYearMan(); | |
cout << "\n------------------------------------------------------------------\n"; | |
cout << header; | |
cout << "\n------------------------------------------------------------------\n"; | |
cout << "Brand" << space << space <<space << "Model" | |
<< space << space << space << "Year Manufactured" << endl; | |
for (unsigned int i = 0; i < SIZE; ++i) { | |
cout << *(b_ptr + i) << space << space << space | |
<< *(m_ptr + i) << space << space << space | |
<< *(ym_ptr + i) << endl; | |
} | |
} | |
int main() { | |
Vehicles v; | |
v.getVInfo(); | |
v.printVInfo(); | |
cout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://plus.google.com/+PhilanJames/posts/7azYsKXe7PX