treepig How do I cheat?
Reputation: 0
Joined: 21 Jul 2011 Posts: 1
|
Posted: Thu Jul 21, 2011 3:23 am Post subject: [Help] C++ Object Oriented Programming |
|
|
I am not sure if I am proceeding on my project correctly. I am not asking for someone to do my homework. I just need some pointers and hints to proceed. Thank You.
| Code: |
#include <iostream>
#include <string>
using namespace std;
class Bicycle {
// Instance field
private:
string ownerName;
int licenseNumber;
// Default Constructor
public:
Bicycle () {}
// Other Constructor
Bicycle( string name, int license ) {
ownerName = name;
licenseNumber = license;
}
// Returns the name of this bicycle's owner
string getOwnerName( ) {
return ownerName;
}
// Assigns the name of this bicycle's owner
void setOwnerName( string name ) {
ownerName = name;
}
// Returns the license number of this bicycle
int getLicenseNumber( ) {
return licenseNumber;
}
// Assigns the license number of this bicycle
void setLicenseNumber( int license ) {
licenseNumber = license;
}
};
int main ()
{
// Create 2 Bicycle references
Bicycle b1, b2("chicken", 23424);
// Create 2 String references for owners' namesq
string s1;
string s2;
// Create 2 integers for license numbers
int num1;
int num2;
// Bicycle 1 is owned by Kenny McCormick, license number 12345
// Use the your full name and a license number for Bicycle 2
// This data must be stored in the above String and integer variables.
// Create the first Bicycle object with the default Bicycle constructor
// Set the owner's name and license number with set methods using
// the variables you created as arguments
b1.setOwnerName("Kenny McCormick");
s1 = b1.getOwnerName();
b1.setLicenseNumber(12345);
num1 = b1.getLicenseNumber();
s2 = b2.getOwnerName();
num2 = b2.getLicenseNumber();
// Create a second Bicycle object with the other Bicycle constructor
// Use the variables you created as arguments
// Output each owner's name and license number in cout statements
// using the objects and the get methods. For example: bike1.getOwnerName()
cout << "Bicycle #1" << endl;
cout << "Name : " << s1 << endl;
cout << "License Number : " << num1 << endl;
cout << "Bicycle #2" << endl;
cout << "Name : " << s2 << endl;
cout << "License Number : " << num2 << endl;
return 1;
} |
|
|