SlideShare a Scribd company logo
SANA'A UNIVERSITY
FACTUALY OF ENINEERING
MECHATRONICS DEPARTMENT
CLASSES REPORT LAB
NAME:
OSAMA HASAN ALMOHAIA
AC.NO 200/2017
SUPERVISORED BY:
ENG.ELHAM ABDULRAHMAN
Objective(s):
 To be familiar with syntax and structure of OOP in C++.
 To learn how to build first OOP of classes.
 To learn about UML class diagram in solving problems using C++.
Software requirements
Title:
Write a class OOP Program that calculate the area and the perimeter of three geometric shapes (circle ,square
,tringle). Your program should be include three classes one for each shape and called from main function.
Problem Analysis:
The problem is to calculate the area and perimeter of three shapes having its inputs parameters identified as:
(rad)for circle, (L) for square, (a,b,c)for tringle and those variable are float type.
The output of the program display menu that mention three classes Square, Circle and Tringle . you should choose
either area or perimeter.
The area of square is Area= Length*Width
and the perimeter is perimete4*Lenght.
The area of circle is Area = 3.14 * (radius)2
and the perimeter is perimeter=2*3.1459*rad.
Also we can find the area of a triangle by using equation:
a = length of first side
b = length of second side
c = length of third side
s = (a + b+ c)/2
Area = sqrt(s*(s-a)*(s-b)*(s-c))
perimetr=a+b+c
-where sqrt stands for square roo
Algorithm:
Step 1: Start
Step 2: Declare three separate class Square,Circle,Tringle with data members and member functions.
Step 3: creat a constructor for each shape which has the same name of classes
Step 3: For each class Define and declare input variables to calculate the area and perimeter of square,
circle and tringle.
Step 4: Create an object for each class .
Step 5: Choose one shape (switch) of the three shape cases .
Step 6: In each case, call the classes objects .
Step 7: Read the inputs parameters of the shape and return its calculation value from its class.
Step 9: Stop
UML Class Diagram of the Program:
Square
- L:float
- x:int
-ch:char
"constructor"+Square():
+ret():char
Figure 1 UML class diagram indicating the class Square
Circle
-rad:float
+ total:float
-pi=3.1459:float
- x:int
-ch:char
"constructor"+Circle()
+ret():char
Figure 2 UML class diagram indicating the class Circle
Tringle
- a:float
-b:float
-c:float
-ch:char
- x:int
+s:float
+ar:float
+pr:float
"constructor"+Tringle()
+ret():char
Figure 3 UML class diagram indicating the class Tringle
CODING
(1) #include <iostream>
(2) #include<cmath>
(3) using namespace std;
(4) class Square
(5) {
(6) private:
(7) int x;
(8) char ch='1';
(9) float L;
(10) public:
(11) Square(){
(12) cout<<"Welcome to the square shape calculations:";
(13) while(ch=='1'){
(14) cout<<"nEnter '1' for area nEnter '2'for perimeter"<<endl;
(15) cin >>x;
(16) if (x==1)
(17) { cout<<" Enter the length:";
(18) cin>>L;
(19) cout<<"the Area of your square is: _"<<L*L<<"_n"<<endl;
(20) cout<<"nn press '0' To choose other shape npress '1'to again n press any key
to exit "<<endl;
(21) cin >>ch;
(22) cout<<"********************************"<<endl;
(23) }
(24) else if (x==2){
(25) cout<<" Enter the length:";
(26) cin>>L;
(27) cout<<"the premiter of your square is: _"<<L*4<<"_"<<endl;
(28) cout<<"nn press '0' To choose other shape npress '1'to again n press any key
to exit "<<endl;
(29) cin >>ch;
(30) } }}
(31) char ret()
(32) {
(33) return ch;
(34) }
(35) };
(36) class Circle
(37) { private:
(38) int x;
(39) char ch='1';
(40) float rad, pi=3.1459;
(41)
(42) public:
(43) float total;
(44) Circle(){
(45) cout<<"Welcome! to the circle shape calculation:";
(46) while(ch=='1'){
(47) cout<<"nEnter '1' for area nEnter '2'for perimeter"<<endl;
(48) cin >>x;
(49) if (x==1){
(50) cout<<" Enter the Radius:";
(51) cin>>rad;
(52) total=(2*rad*pi);
(53) cout<<"the area of your circle is: "<<total<<endl;
(54) cout<<"nn press '0' To choose other shape npress '1'to again n press any key
to exit "<<endl;
(55) cin >>ch;
(56) cout<<"********************************"<<endl;
(57) }
(58) if (x==2){
(59) cout<<"Enter the Radius:";
(60) cin>>rad;
(61) total=(rad*rad*pi);
(62) cout<<"the perimeter of your circle is: "<<total<<"n"<<endl;
(63) cout<<"nn press '0' To choose other shape npress '1'to again n press any key
to exit "<<endl;
(64) cin >>ch;
(65) cout<<"********************************"<<endl;
(66) }} }
(67)
(68) char ret()
(69) {
(70) return ch;
(71) }
(72) };
(73) class Tringle
(74) {
(75) private:
(76) int x;
(77) char ch='1';
(78) float a,b,c;
(79) public:
(80) float s,ar,pr;
(81) Tringle(){
(82) cout<<"welcome to the triangle shape calculation:";
(83) while(ch=='1'){
(84) cout<<"nEnter '1' for area nENter '2'for perimeter"<<endl;
(85) cin >>x;
(86) if (x==1){
(87) cout<<" Enter the length a:";
(88) cin>>a;
(89) cout<<"Enter the length b:";
(90) cin>>b;
(91) cout<<"Enter the length c:";
(92) cin>>c;
(93) s=(a+b+c)/2;
(94) ar=sqrt(s*(s-a)*(s-b)*(s-c));
(95) cout<<"the area of your triangle is: "<<ar<<endl;
(96) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to
exit "<<endl;
(97) cin >>ch;
(98) cout<<"********************************"<<endl;
(99) }
(100) else if (x==2)
(101) {
(102) cout<<" Enter the length a:";
(103) cin>>a;
(104) cout<<"Enter the length b:";
(105) cin>>b;
(106) cout<<"Enter the length c:";
(107) cin>>c;
(108) pr=a+b+c;
(109) cout<<"the perimeter of your triangle is: "<<pr<<endl;
(110)
(111) cout<<"nn press '0' To choose other shape npress '1'to again n press any key
to exit "<<endl;
(112) cin >>ch;
(113) cout<<"********************************"<<endl;
(114) }}}
(115) char ret()
(116) {
(117) return ch;
(118) }
(119) };
(120)
(121)
(122) int main()
(123) { char y='0';
(124) char ch;
(125) while(y=='0'){
(126) cout << "Hello!n please choose one shape of the following :n1- square.n2-
circle.n3- trianglenpress any other key to exitn." << endl;
(127) cin>>ch;
(128) if(ch=='1'){
(129) Square S;
(130) y=S.ret();
(131) }
(132) else if(ch=='2'){
(133) Circle C;
(134) y=C.ret();
(135) }
(136) else if(ch=='3'){
(137) Tringle T;
(138) y=T.ret();
(139) }
(140) else
(141) { cout<<"The program will close ....enter to continue"<<endl;
(142) y='5';
(143) }}}
Discussions:
(1) #include <iostream>
(2) #include<cmath>
(3) using namespace std;
From now we can treat with c++ so, we include the standard c++ library <iostream>
And <cmath> to calculate the area of shapes.
We you start the program it will display the main function
In the main function we declare about objects of each class shape and display menu to choose one shape for
calculation.
When you choose one option (i.e 1. square) the main go to class data type square and perform the operation and
method in this class.
Firstly, function method void sq() initialized and display welcome message attend you to enter the input parameter
and give you two option either area or perimeter .
Each case perform its calculation and the total return to the main function.
(4) class Square
(5) {
(6) private:
(7) int x;
(8) char ch='1';
(9) float L;
(10) public:
(11) Square(){
(12) cout<<"Welcome to the square shape calculations:";
(13) while(ch=='1'){
(14) cout<<"nEnter '1' for area nEnter '2'for perimeter"<<endl;
(15) cin >>x;
(16) if (x==1)
(17) { cout<<" Enter the length:";
(18) cin>>L;
(19) cout<<"the Area of your square is: _"<<L*L<<"_n"<<endl;
(20) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit
"<<endl;
(21) cin >>ch;
(22) cout<<"********************************"<<endl;
(23) }
(24) else if (x==2){
(25) cout<<" Enter the length:";
(26) cin>>L;
(27) cout<<"the premiter of your square is: _"<<L*4<<"_"<<endl;
(28) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit
"<<endl;
(29) cin >>ch;
(30) } }}
(31) char ret()
(32) {
(33) return ch;
(34) }
(35) };
Line 4to 35 show the Declaration of Square class.
Line 4,the Square class definition should be declared firstly and this class contain data members (private for the
parameter input of square shape and public for the function member (method) which perform calculations)
Note: Reading and calculating and Display the information for square shape done in Constructor Square()-line11.
After you complete the calculation, the program tell you if you want to calculate another shape press certain
number shown in the screen and if you want to exit press any key.
These number entered recently return to main function by the member function char ret()(Line 40).
Output (Compilation, Debugging & Testing)
The main menu output screen .
Figure 2 the main menu output screen
Choose one option let we choose 3-tringle
Figure 3 the tringle menu
to calculate area press 1 and for perimeter press 2
the program tell you to enter a , b and c
Figure 4 the tringle parameters input screen
If you want to do another calculation for the same shape press0 or 1 to another shape or any key to exit
Conclusion
This is the first program written in abstract Data type OOP classes C++. The program is focused on the calculation
of area and perimeter of three shape.
From this lab, I understood the basic classes declaration and definition including data member and method.
References:
C++ - How to Program 6th ed. - P. Deitel, et. al., (Pearson, 2010).
Lab sheet.
www.researchgate.net/publication/322908864_C_Programming_Lab_Manual .
www.google.com.

More Related Content

What's hot (20)

PPTX
Matlab ploting
Ameen San
 
PDF
Mat lab
Gizachew Kefelew
 
DOCX
Introduction to r
Golden Julie Jesus
 
PDF
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Austin Benson
 
PPTX
Matlab plotting
shahid sultan
 
DOCX
Computer graphics
shafiq sangi
 
PPT
AutoCAD introduction
rfzah
 
PDF
Computer graphics lab manual
Ankit Kumar
 
PPTX
Introduction to matlab lecture 4 of 4
Randa Elanwar
 
PDF
Sample presentation slides template
Valerii Klymchuk
 
PDF
Computer graphics lab report with code in cpp
Alamgir Hossain
 
PPTX
Autocad electrical
manishankar98
 
PDF
Scala collection methods flatMap and flatten are more powerful than monadic f...
Philip Schwarz
 
PDF
Matlab 1
asguna
 
PDF
Cg lab cse-v (1) (1)
Surya Sukumaran
 
PDF
Computer graphics lab manual
Uma mohan
 
DOCX
Solid works lab manual including auto cad
PUDOTATHARUN
 
PDF
Solution of matlab chapter 4
AhsanIrshad8
 
PDF
AutoCad Basic tutorial
Julio Alcaraz Evaristo
 
Matlab ploting
Ameen San
 
Introduction to r
Golden Julie Jesus
 
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Austin Benson
 
Matlab plotting
shahid sultan
 
Computer graphics
shafiq sangi
 
AutoCAD introduction
rfzah
 
Computer graphics lab manual
Ankit Kumar
 
Introduction to matlab lecture 4 of 4
Randa Elanwar
 
Sample presentation slides template
Valerii Klymchuk
 
Computer graphics lab report with code in cpp
Alamgir Hossain
 
Autocad electrical
manishankar98
 
Scala collection methods flatMap and flatten are more powerful than monadic f...
Philip Schwarz
 
Matlab 1
asguna
 
Cg lab cse-v (1) (1)
Surya Sukumaran
 
Computer graphics lab manual
Uma mohan
 
Solid works lab manual including auto cad
PUDOTATHARUN
 
Solution of matlab chapter 4
AhsanIrshad8
 
AutoCad Basic tutorial
Julio Alcaraz Evaristo
 

Similar to Class program and uml in c++ (20)

DOC
oop Lecture 4
Anwar Ul Haq
 
PDF
Please follow the cod eand comments for description CODE #incl.pdf
annaielectronicsvill
 
DOCX
Write a new version of the area calculation program that makes use of.docx
ajoy21
 
DOC
oop Lecture 5
Anwar Ul Haq
 
PDF
OOP_EXPLAINED_example_of_cod_and_explainations.pdf
DerekDixmanChakowela
 
PDF
CS215 Lec 1 introduction
Arab Open University and Cairo University
 
PDF
c++ lab manual
Shrunkhala Wankhede
 
PPT
C++ classes tutorials
kksupaul
 
PPT
C++ classes tutorials
kailash454
 
PPTX
C++ programming basics
Munazza-Mah-Jabeen
 
PPTX
C++ process new
敬倫 林
 
DOCX
Opp compile
Muhammad Faiz
 
PDF
Please use the following UML diagram and main.cpp to complete the c.pdf
mohammedfootwear
 
DOCX
Oop project
Quratulain Naqvi
 
PDF
Software Engineering
Tharindu Weerasinghe
 
DOC
Pads lab manual final
AhalyaR
 
PDF
Classes
Swarup Boro
 
PPT
3 functions and class
trixiacruz
 
oop Lecture 4
Anwar Ul Haq
 
Please follow the cod eand comments for description CODE #incl.pdf
annaielectronicsvill
 
Write a new version of the area calculation program that makes use of.docx
ajoy21
 
oop Lecture 5
Anwar Ul Haq
 
OOP_EXPLAINED_example_of_cod_and_explainations.pdf
DerekDixmanChakowela
 
c++ lab manual
Shrunkhala Wankhede
 
C++ classes tutorials
kksupaul
 
C++ classes tutorials
kailash454
 
C++ programming basics
Munazza-Mah-Jabeen
 
C++ process new
敬倫 林
 
Opp compile
Muhammad Faiz
 
Please use the following UML diagram and main.cpp to complete the c.pdf
mohammedfootwear
 
Oop project
Quratulain Naqvi
 
Software Engineering
Tharindu Weerasinghe
 
Pads lab manual final
AhalyaR
 
Classes
Swarup Boro
 
3 functions and class
trixiacruz
 
Ad

Recently uploaded (20)

PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
PPT
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
PDF
Authentication Devices in Fog-mobile Edge Computing Environments through a Wi...
ijujournal
 
PDF
Module - 4 Machine Learning -22ISE62.pdf
Dr. Shivashankar
 
PDF
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
 
PDF
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
PDF
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
PDF
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
 
PPTX
Functions in Python Programming Language
BeulahS2
 
PDF
輪読会資料_Miipher and Miipher2 .
NABLAS株式会社
 
PPTX
CST413 KTU S7 CSE Machine Learning Neural Networks and Support Vector Machine...
resming1
 
PPTX
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 
PDF
01-introduction to the ProcessDesign.pdf
StiveBrack
 
PPTX
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
PPTX
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
PDF
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
PDF
PRIZ Academy - Process functional modelling
PRIZ Guru
 
PPTX
Work at Height training for workers .pptx
cecos12
 
PPTX
Artificial Intelligence jejeiejj3iriejrjifirirjdjeie
VikingsGaming2
 
PDF
Decision support system in machine learning models for a face recognition-bas...
TELKOMNIKA JOURNAL
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
Authentication Devices in Fog-mobile Edge Computing Environments through a Wi...
ijujournal
 
Module - 4 Machine Learning -22ISE62.pdf
Dr. Shivashankar
 
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
Python Mini Project: Command-Line Quiz Game for School/College Students
MPREETHI7
 
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
 
Functions in Python Programming Language
BeulahS2
 
輪読会資料_Miipher and Miipher2 .
NABLAS株式会社
 
CST413 KTU S7 CSE Machine Learning Neural Networks and Support Vector Machine...
resming1
 
FSE_LLM4SE1_A Tool for In-depth Analysis of Code Execution Reasoning of Large...
cl144
 
01-introduction to the ProcessDesign.pdf
StiveBrack
 
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
PRIZ Academy - Process functional modelling
PRIZ Guru
 
Work at Height training for workers .pptx
cecos12
 
Artificial Intelligence jejeiejj3iriejrjifirirjdjeie
VikingsGaming2
 
Decision support system in machine learning models for a face recognition-bas...
TELKOMNIKA JOURNAL
 
Ad

Class program and uml in c++

  • 1. SANA'A UNIVERSITY FACTUALY OF ENINEERING MECHATRONICS DEPARTMENT CLASSES REPORT LAB NAME: OSAMA HASAN ALMOHAIA AC.NO 200/2017 SUPERVISORED BY: ENG.ELHAM ABDULRAHMAN
  • 2. Objective(s):  To be familiar with syntax and structure of OOP in C++.  To learn how to build first OOP of classes.  To learn about UML class diagram in solving problems using C++. Software requirements Title: Write a class OOP Program that calculate the area and the perimeter of three geometric shapes (circle ,square ,tringle). Your program should be include three classes one for each shape and called from main function. Problem Analysis: The problem is to calculate the area and perimeter of three shapes having its inputs parameters identified as: (rad)for circle, (L) for square, (a,b,c)for tringle and those variable are float type. The output of the program display menu that mention three classes Square, Circle and Tringle . you should choose either area or perimeter. The area of square is Area= Length*Width and the perimeter is perimete4*Lenght. The area of circle is Area = 3.14 * (radius)2 and the perimeter is perimeter=2*3.1459*rad. Also we can find the area of a triangle by using equation: a = length of first side b = length of second side c = length of third side s = (a + b+ c)/2 Area = sqrt(s*(s-a)*(s-b)*(s-c)) perimetr=a+b+c -where sqrt stands for square roo Algorithm: Step 1: Start Step 2: Declare three separate class Square,Circle,Tringle with data members and member functions. Step 3: creat a constructor for each shape which has the same name of classes Step 3: For each class Define and declare input variables to calculate the area and perimeter of square, circle and tringle. Step 4: Create an object for each class . Step 5: Choose one shape (switch) of the three shape cases . Step 6: In each case, call the classes objects . Step 7: Read the inputs parameters of the shape and return its calculation value from its class. Step 9: Stop
  • 3. UML Class Diagram of the Program: Square - L:float - x:int -ch:char "constructor"+Square(): +ret():char Figure 1 UML class diagram indicating the class Square Circle -rad:float + total:float -pi=3.1459:float - x:int -ch:char "constructor"+Circle() +ret():char Figure 2 UML class diagram indicating the class Circle Tringle - a:float -b:float -c:float -ch:char - x:int +s:float +ar:float +pr:float "constructor"+Tringle() +ret():char Figure 3 UML class diagram indicating the class Tringle
  • 4. CODING (1) #include <iostream> (2) #include<cmath> (3) using namespace std; (4) class Square (5) { (6) private: (7) int x; (8) char ch='1'; (9) float L; (10) public: (11) Square(){ (12) cout<<"Welcome to the square shape calculations:"; (13) while(ch=='1'){ (14) cout<<"nEnter '1' for area nEnter '2'for perimeter"<<endl; (15) cin >>x; (16) if (x==1) (17) { cout<<" Enter the length:"; (18) cin>>L; (19) cout<<"the Area of your square is: _"<<L*L<<"_n"<<endl; (20) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit "<<endl; (21) cin >>ch; (22) cout<<"********************************"<<endl; (23) } (24) else if (x==2){ (25) cout<<" Enter the length:"; (26) cin>>L; (27) cout<<"the premiter of your square is: _"<<L*4<<"_"<<endl; (28) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit "<<endl; (29) cin >>ch; (30) } }}
  • 5. (31) char ret() (32) { (33) return ch; (34) } (35) }; (36) class Circle (37) { private: (38) int x; (39) char ch='1'; (40) float rad, pi=3.1459; (41) (42) public: (43) float total; (44) Circle(){ (45) cout<<"Welcome! to the circle shape calculation:"; (46) while(ch=='1'){ (47) cout<<"nEnter '1' for area nEnter '2'for perimeter"<<endl; (48) cin >>x; (49) if (x==1){ (50) cout<<" Enter the Radius:"; (51) cin>>rad; (52) total=(2*rad*pi); (53) cout<<"the area of your circle is: "<<total<<endl; (54) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit "<<endl; (55) cin >>ch; (56) cout<<"********************************"<<endl; (57) } (58) if (x==2){ (59) cout<<"Enter the Radius:"; (60) cin>>rad; (61) total=(rad*rad*pi); (62) cout<<"the perimeter of your circle is: "<<total<<"n"<<endl;
  • 6. (63) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit "<<endl; (64) cin >>ch; (65) cout<<"********************************"<<endl; (66) }} } (67) (68) char ret() (69) { (70) return ch; (71) } (72) }; (73) class Tringle (74) { (75) private: (76) int x; (77) char ch='1'; (78) float a,b,c; (79) public: (80) float s,ar,pr; (81) Tringle(){ (82) cout<<"welcome to the triangle shape calculation:"; (83) while(ch=='1'){ (84) cout<<"nEnter '1' for area nENter '2'for perimeter"<<endl; (85) cin >>x; (86) if (x==1){ (87) cout<<" Enter the length a:"; (88) cin>>a; (89) cout<<"Enter the length b:"; (90) cin>>b; (91) cout<<"Enter the length c:"; (92) cin>>c; (93) s=(a+b+c)/2; (94) ar=sqrt(s*(s-a)*(s-b)*(s-c)); (95) cout<<"the area of your triangle is: "<<ar<<endl;
  • 7. (96) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit "<<endl; (97) cin >>ch; (98) cout<<"********************************"<<endl; (99) } (100) else if (x==2) (101) { (102) cout<<" Enter the length a:"; (103) cin>>a; (104) cout<<"Enter the length b:"; (105) cin>>b; (106) cout<<"Enter the length c:"; (107) cin>>c; (108) pr=a+b+c; (109) cout<<"the perimeter of your triangle is: "<<pr<<endl; (110) (111) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit "<<endl; (112) cin >>ch; (113) cout<<"********************************"<<endl; (114) }}} (115) char ret() (116) { (117) return ch; (118) } (119) }; (120) (121) (122) int main() (123) { char y='0'; (124) char ch; (125) while(y=='0'){ (126) cout << "Hello!n please choose one shape of the following :n1- square.n2- circle.n3- trianglenpress any other key to exitn." << endl;
  • 8. (127) cin>>ch; (128) if(ch=='1'){ (129) Square S; (130) y=S.ret(); (131) } (132) else if(ch=='2'){ (133) Circle C; (134) y=C.ret(); (135) } (136) else if(ch=='3'){ (137) Tringle T; (138) y=T.ret(); (139) } (140) else (141) { cout<<"The program will close ....enter to continue"<<endl; (142) y='5'; (143) }}} Discussions: (1) #include <iostream> (2) #include<cmath> (3) using namespace std; From now we can treat with c++ so, we include the standard c++ library <iostream> And <cmath> to calculate the area of shapes. We you start the program it will display the main function In the main function we declare about objects of each class shape and display menu to choose one shape for calculation. When you choose one option (i.e 1. square) the main go to class data type square and perform the operation and method in this class. Firstly, function method void sq() initialized and display welcome message attend you to enter the input parameter and give you two option either area or perimeter . Each case perform its calculation and the total return to the main function.
  • 9. (4) class Square (5) { (6) private: (7) int x; (8) char ch='1'; (9) float L; (10) public: (11) Square(){ (12) cout<<"Welcome to the square shape calculations:"; (13) while(ch=='1'){ (14) cout<<"nEnter '1' for area nEnter '2'for perimeter"<<endl; (15) cin >>x; (16) if (x==1) (17) { cout<<" Enter the length:"; (18) cin>>L; (19) cout<<"the Area of your square is: _"<<L*L<<"_n"<<endl; (20) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit "<<endl; (21) cin >>ch; (22) cout<<"********************************"<<endl; (23) } (24) else if (x==2){ (25) cout<<" Enter the length:"; (26) cin>>L; (27) cout<<"the premiter of your square is: _"<<L*4<<"_"<<endl; (28) cout<<"nn press '0' To choose other shape npress '1'to again n press any key to exit "<<endl; (29) cin >>ch; (30) } }} (31) char ret() (32) { (33) return ch; (34) } (35) };
  • 10. Line 4to 35 show the Declaration of Square class. Line 4,the Square class definition should be declared firstly and this class contain data members (private for the parameter input of square shape and public for the function member (method) which perform calculations) Note: Reading and calculating and Display the information for square shape done in Constructor Square()-line11. After you complete the calculation, the program tell you if you want to calculate another shape press certain number shown in the screen and if you want to exit press any key. These number entered recently return to main function by the member function char ret()(Line 40). Output (Compilation, Debugging & Testing) The main menu output screen . Figure 2 the main menu output screen Choose one option let we choose 3-tringle Figure 3 the tringle menu to calculate area press 1 and for perimeter press 2 the program tell you to enter a , b and c Figure 4 the tringle parameters input screen
  • 11. If you want to do another calculation for the same shape press0 or 1 to another shape or any key to exit Conclusion This is the first program written in abstract Data type OOP classes C++. The program is focused on the calculation of area and perimeter of three shape. From this lab, I understood the basic classes declaration and definition including data member and method. References: C++ - How to Program 6th ed. - P. Deitel, et. al., (Pearson, 2010). Lab sheet. www.researchgate.net/publication/322908864_C_Programming_Lab_Manual . www.google.com.