-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarExample.cpp
More file actions
58 lines (47 loc) · 1.39 KB
/
carExample.cpp
File metadata and controls
58 lines (47 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Allows for input and output operations
#include <iostream>
// Allows the use of string data type
#include <string>
// Namespace Declaration so we don't have to use std:: before every standard library object
using namespace std;
// Defining the Car class, which is a new data type
class Car {
// Defining Class Specific Variables - Private Variables
private:
string brand;
string model;
int year;
public:
// Constructor
Car(string b, string m, int y) {
// Denoting the class variables
brand = b;
model = m;
year = y;
}
// Method to display car details
void displayInfo() {
// Displaying the value of the priavte variables
cout << "Car Brand: " << brand << endl;
cout << "Car Model: " << model << endl;
cout << "Car Year: " << year << endl;
}
};
int main() {
// Variables to hold user input
string userBrand, userModel;
int userYear;
// Getting user input
cout << "Enter the car brand: ";
getline(cin, userBrand); // allows spaces
cout << "Enter the car model: ";
getline(cin, userModel);
cout << "Enter the car year: ";
cin >> userYear;
// Create a Car object using user input
Car userCar(userBrand, userModel, userYear);
// Display the car information
cout << "\nHere is the information of your car:" << endl;
userCar.displayInfo();
return 0;
}