Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0c91da1

Browse files
writing a class in C++
1 parent 4807f42 commit 0c91da1

File tree

1 file changed

+40
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 11 OOP/Writing_a_class_in_CPP

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// main.cpp
3+
// Writing_a_class_in_CPP
4+
//
5+
// Created by George Catalin on 04.11.2023.
6+
//
7+
8+
#include <iostream>
9+
10+
using namespace std;
11+
12+
class Rectangle
13+
{
14+
public:
15+
int length;
16+
int breadth;
17+
18+
int area()
19+
{
20+
return length * breadth;
21+
}
22+
23+
int perimeter()
24+
{
25+
return 2*(length+breadth);
26+
}
27+
};
28+
29+
int main(int argc, const char * argv[])
30+
{
31+
Rectangle r1;
32+
33+
r1.length = 10;
34+
r1.breadth = 30;
35+
36+
cout<<"The area is "<<r1.area()<<endl;
37+
cout<<"The perimeter is "<<r1.perimeter()<<endl;
38+
39+
return 0;
40+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /