SlideShare a Scribd company logo
1 of 11
Download to read offline
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

Matlab ploting
Matlab plotingMatlab ploting
Matlab plotingAmeen San
 
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)Austin Benson
 
Computer graphics
Computer graphics Computer graphics
Computer graphics shafiq sangi
 
AutoCAD introduction
AutoCAD introductionAutoCAD introduction
AutoCAD introductionrfzah
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualAnkit Kumar
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Randa Elanwar
 
Sample presentation slides template
Sample presentation slides templateSample presentation slides template
Sample presentation slides templateValerii Klymchuk
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cppAlamgir Hossain
 
Scala collection methods flatMap and flatten are more powerful than monadic f...
Scala collection methods flatMap and flatten are more powerful than monadic f...Scala collection methods flatMap and flatten are more powerful than monadic f...
Scala collection methods flatMap and flatten are more powerful than monadic f...Philip Schwarz
 
Matlab 1
Matlab 1Matlab 1
Matlab 1asguna
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
Solid works lab manual including auto cad
Solid works lab manual including auto cadSolid works lab manual including auto cad
Solid works lab manual including auto cadPUDOTATHARUN
 
Solution of matlab chapter 4
Solution of matlab chapter 4Solution of matlab chapter 4
Solution of matlab chapter 4AhsanIrshad8
 

What's hot (20)

Matlab ploting
Matlab plotingMatlab ploting
Matlab ploting
 
Mat lab
Mat labMat lab
Mat lab
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Computer graphics
Computer graphics Computer graphics
Computer graphics
 
AutoCAD introduction
AutoCAD introductionAutoCAD introduction
AutoCAD introduction
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
 
Sample presentation slides template
Sample presentation slides templateSample presentation slides template
Sample presentation slides template
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Autocad electrical
Autocad electricalAutocad electrical
Autocad electrical
 
Scala collection methods flatMap and flatten are more powerful than monadic f...
Scala collection methods flatMap and flatten are more powerful than monadic f...Scala collection methods flatMap and flatten are more powerful than monadic f...
Scala collection methods flatMap and flatten are more powerful than monadic f...
 
Matlab 1
Matlab 1Matlab 1
Matlab 1
 
Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Solid works lab manual including auto cad
Solid works lab manual including auto cadSolid works lab manual including auto cad
Solid works lab manual including auto cad
 
Solution of matlab chapter 4
Solution of matlab chapter 4Solution of matlab chapter 4
Solution of matlab chapter 4
 
AutoCad Basic tutorial
AutoCad Basic tutorialAutoCad Basic tutorial
AutoCad Basic tutorial
 

Similar to Class program and uml in c++

Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfhullibergerr25980
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordLakshmi Sarvani Videla
 
IntroductionToMathematica.pptx
IntroductionToMathematica.pptxIntroductionToMathematica.pptx
IntroductionToMathematica.pptxMuhammadImran1347
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.pptMahyuddin8
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxgilpinleeanna
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++NUST Stuff
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06HUST
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfarchgeetsenterprises
 
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Palak Sanghani
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
External Interface to SIMULINK
External Interface to SIMULINKExternal Interface to SIMULINK
External Interface to SIMULINKRobert Edwards
 

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

Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdf
 
Prep3 computer midterm revision
Prep3 computer midterm revisionPrep3 computer midterm revision
Prep3 computer midterm revision
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
 
Ch3
Ch3Ch3
Ch3
 
IntroductionToMathematica.pptx
IntroductionToMathematica.pptxIntroductionToMathematica.pptx
IntroductionToMathematica.pptx
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.ppt
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 
Csphtp1 06
Csphtp1 06Csphtp1 06
Csphtp1 06
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdf
 
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
Python Manuel-R2021.pdf
Python Manuel-R2021.pdfPython Manuel-R2021.pdf
Python Manuel-R2021.pdf
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
Es272 ch1
Es272 ch1Es272 ch1
Es272 ch1
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
External Interface to SIMULINK
External Interface to SIMULINKExternal Interface to SIMULINK
External Interface to SIMULINK
 
Using matlab simulink
Using matlab simulinkUsing matlab simulink
Using matlab simulink
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 

Recently uploaded (20)

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 

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.