-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp-code-challenge-class_object.cpp
More file actions
82 lines (64 loc) · 1.76 KB
/
cpp-code-challenge-class_object.cpp
File metadata and controls
82 lines (64 loc) · 1.76 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//============================================================================
// Name : cpp-code-challenge-class_object.cpp
// Author : Aman Ranjan
// Version :v1.0
// Copyright : This code is freeware and can be used without prior notice.
// Description : Program to apply class and object based function method.
//============================================================================
//here we can also use #include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <unistd.h>
#include <conio.h>
#include <process.h>
using namespace std;
class Pet
{
public:
string name;
string breed;
string color;
int age;
int id=1;
string nickname()
{ //M- I inside the class declaration and definition
string nick = name + breed;
return nick;
};
void Printdetail(); //Method- II declaration (out of the class)
};
void Pet :: Printdetail()
{
cout <<"Identity: "<<id<< "\nName of the pet: "<<name<< //Method- II definition
"\nThe breed is: "<<breed<<"\n colour of the pet "
"is : "<<color<<"\nThe age is: "<<age<<endl;
++id;
while((getchar()='\n'));
}
int main()
{
setbuf(stdout,NULL);
{
Pet dog1, dog2;
dog1.name = "stiffen";
dog1.breed = "javen";
dog1.color = "white";
dog1.age = 3;
while((getchar()='\n'));
dog1.Printdetail();
string name= dog1.nickname();
cout <<"Nickname: "<<name<<endl;
/////////////////////// //////////////////////////
cout<<endl<<endl<<endl<<endl;
///////////////////////////////////////////////////////////////////////////
dog2.name = "James";
dog2.breed = "loren";
dog2.color = "spoty white";
dog2.age = 7;
while((getchar()='\n'));
dog2.Printdetail();
string name2= dog2.nickname();
cout <<"Nickname: "<<name2<<endl;
}
return 0;
}