-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathCodeDemo.cpp
More file actions
47 lines (42 loc) · 997 Bytes
/
CodeDemo.cpp
File metadata and controls
47 lines (42 loc) · 997 Bytes
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
// Learning C++
// Exercise 03_03
// Using Classes, by Eduardo Corpeño
#include <iostream>
#include <string>
enum class cow_purpose {dairy, meat, hide, pet};
class cow{
public:
cow(std::string name_i, int age_i, cow_purpose purpose_i)
{
name = name_i;
age = age_i;
purpose = purpose_i;
}
std::string get_name() const
{
return name;
}
int get_age() const
{
return age;
}
cow_purpose get_purpose() const
{
return purpose;
}
private:
std::string name;
int age;
cow_purpose purpose;
};
int main()
{
cow my_cow( "Betsy", 5, cow_purpose::dairy);
// my_cow.age = 5;
// my_cow.name = "Betsy";
// my_cow.purpose = cow_purpose::dairy;
std::cout << my_cow.name << " is a type-" << (int)my_cow.purpose << " cow." << std::endl;
std::cout << my_cow.name << " is " << my_cow.age << " years old." << std::endl;
std::cout << std::endl << std::endl;
return (0);
}