SlideShare a Scribd company logo
1 of 9
Work on Static methods OBJECTIVES -continue to practice to
write the code for the data type class -Learn what is static
members in data type class and how to write static methods -
Learn how to access static members of data type class from
main() Provide the application that helps users to calculate the
area of the following list of shapes. Square Rectangle Triangle
Circle Trapezoid Rhombus Kite Parallelogram For each shape,
you can ask for all necessary information of the selected shape
to calculate its area from the keyboard. The result should be
displayed in the following format, for example with selected
shape is Rectangle -Manage the menu with the do., while loop
to redisplayed the menu after finishing one shape -How to write
the switch statement -How to format the output in columns and
with 2 decimal digits -How to create the static method in data
type class -How to access static method of data type class from
main() -The formula to calculate the area of all above shapes -
You have to provide the pseudo code of main() at the top of
driver class or in the word document with party -Create a
project named SU2016LAB6_PART2_YourLastName then add
two classes in -Class SU2016LAB6_ShapeArea_yourLastName
that includes all the static methods that receive the information
input from main(), calculate the area of required shapes and
return its area. -Driver class
SU2016LAB6_AccessStaticMethod_yourLastName: this class
include main() where you can provide the menu to allow users
to select the shapes to calculate the area. For each shape, ask
for and read the necessary information to calculate the area
from the keyboard, then call the static method of class
SU2016LAB6_ShapeArea_yourLastName to pass the
information in to get the area. After that, display the result as
requested format
Solution
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
class Shape{ //shape class
public:
virtual double area();
};
class Rectangle : public Shape {//rectangle class
private:
double width, length; //sides
public:
Rectangle(double width, double length) {
this->width = width;
this->length = length;
}
double area() {
// A = w * l
return width * length;
}
};
class Rhombus: public Shape{//rhombus class
private:
double width, length; //2 diagonals
public:
Rhombus(double width, double length) {
this->width = width;
this->length = length;
}
double area() {
return 1/2*width * length;
}
};
class Kite:public Shape{//kite class
private:
double width, length; //2 diagonals
public:
Kite(double width, double length) {
this->width = width;
this->length = length;
}
double area() {
return 1/2*width * length;
}
};
class Parallelogram:public Shape {//parallelogram class
private:double width, length; //sides
public:
Parallelogram(double width, double length) {
this->width = width;
this->length = length;
}
double area() {
return width * length;
}
};
class Circle:public Shape {//circle class
private: double radius;
public:
Circle(double radius) {
this->radius = radius;
}
double area() {
// A = p r^2
return 22/7 * radius*radius;
}
};
class Square:public Shape{//square class
private: double side;
public:
Square(double side) {
this->side = side;
}
double area() {
return side*side;
}
};
class Triangle:public Shape{//triangle class
private: double a, b, c; // sides
public:
Triangle(double a, double b, double c) {
this->a = a;
this->b = b;
this->c = c;
}
double area() {
// Heron's formula:
// A = SquareRoot(s * (s - a) * (s - b) * (s - c))
// where s = (a + b + c) / 2, or 1/2 of the perimeter of the
triangle
double s = (a + b + c) / 2;
return sqrt(s * (s - a) * (s - b) * (s - c));
}
};
class Trapezoid:public Shape{//trapezoid class
private: double a, b, c; // sides
public:
Trapezoid(double a, double b, double c) {
this->a = a;
this->b = b;
this->c = c;
}
double area() {
return 1/2*(a+b)*c;
}
};
int main() {
// Square test
double side;
cout<<"Enter the side"<<endl;
cin>>side;
Shape square = Square(side);
cout<<"Shape : Square "<<"side = "<<side<<" Area = "
<< square.area()<< " ";
// Rectangle test
double width,length;
cout<<"Enter the width and length"<<endl;
cin>>width>>length;
Shape rectangle = Rectangle(width, length);
cout<<"Shape : Rectangle "<< "Width = "<<width<<"
Length = "<< length
<< " Area = " << rectangle.area()<< " ";
// Triangle test
double a, b, c;
cout<<"enter the sides of th triangle"<<endl;
cin>>a>>b>>c;
Shape triangle = Triangle(a,b,c);
cout<<"Shape : Triangle " << "Side1 = "<<a <<" "<<
"Side2 = " << b<<" Side3 = "<< c
<< " Area = " << triangle.area()<< " ";
// Circle test
double radius;
cout<<"Enter the radius"<<endl;
cin>>radius;
Shape circle = Circle(radius);
cout<<"Shape : Circle " << "Radius = "<<radius << "
Area = " << circle.area()<< " ";
// Trapezoid test
double a1, b1, c1;
cout<<"enter the sides of th trapezoid"<<endl;
cin>>a1>>b1>>c1;
Shape trapezoid =Trapezoid(a,b,c);
cout<<"Shape : Trapezoid "<< "Base1 = "<<a1 <<" Base2
= "<< b1<<" Height = "<< c1
<<" Area = " <<trapezoid.area()<< " ";
// Rhombus test
double diag1,diag2;
cout<<"Enter the diagonals"<<endl;
cin>>diag1>>diag2;
Shape rhombus =Rhombus(diag1, diag2);
cout<<"Shape : Rhombus " << "diagonal1 = "<<diag1<<"
diagonal2 = " << diag2
<< " Area = "<< rhombus.area()<< " ";
// Kite test
double diag3,diag4;
cout<<"Enter the diagonals"<<endl;
cin>>diag1>>diag2;
Shape kite =Kite(diag3, diag4);
cout<<"Shape : Kite "<< "diagonal1 = "<<diag3<<"
diagonal2 = " << diag4
<<" Area = "<< kite.area()<< " ";
// Parallelogram test
double width3, length3;
cout<<"Enter the width and length"<<endl;
cin>>width3>>length3;
Shape parallelogram = Parallelogram(width3, length3);
cout<<"Shape : parallelogram " << "Base = "<<width3
<<" Length = "<< length3
<<" Area = " << parallelogram.area()<< " ";
return 0;
}

More Related Content

Similar to Work on Static methods OBJECTIVES -continue to practice to write the .docx

10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdf
10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdf10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdf
10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdfRihabBENLAMINE
 
3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdf3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdfatozshoppe
 
Abstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling JavaAbstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling JavaSyedShahroseSohail
 
You still work for packaging company that makes boxes and cylindrical.docx
 You still work for packaging company that makes boxes and cylindrical.docx You still work for packaging company that makes boxes and cylindrical.docx
You still work for packaging company that makes boxes and cylindrical.docxajoy21
 
In this project you implement a program such that it simulates the p.pdf
In this project you implement a program such that it simulates the p.pdfIn this project you implement a program such that it simulates the p.pdf
In this project you implement a program such that it simulates the p.pdffathimafancy
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQLvikram mahendra
 
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxCSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxfaithxdunce63732
 
Example for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfExample for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfrajaratna4
 
14 class design (1)
14 class design (1)14 class design (1)
14 class design (1)Satyam Gupta
 

Similar to Work on Static methods OBJECTIVES -continue to practice to write the .docx (11)

10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdf
10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdf10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdf
10_interfacesjavaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.pdf
 
3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdf3- In the program figurespointers we have a base class location and va.pdf
3- In the program figurespointers we have a base class location and va.pdf
 
Abstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling JavaAbstract Classes Interface Exceptional Handling Java
Abstract Classes Interface Exceptional Handling Java
 
You still work for packaging company that makes boxes and cylindrical.docx
 You still work for packaging company that makes boxes and cylindrical.docx You still work for packaging company that makes boxes and cylindrical.docx
You still work for packaging company that makes boxes and cylindrical.docx
 
In this project you implement a program such that it simulates the p.pdf
In this project you implement a program such that it simulates the p.pdfIn this project you implement a program such that it simulates the p.pdf
In this project you implement a program such that it simulates the p.pdf
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
 
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docxCSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
CSC139 Chapter 10 Lab Assignment (2)PolymorphismObjectivesIn.docx
 
L10
L10L10
L10
 
Example for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdfExample for Abstract Class and Interface.pdf
Example for Abstract Class and Interface.pdf
 
14 class design (1)
14 class design (1)14 class design (1)
14 class design (1)
 
14 class design
14 class design14 class design
14 class design
 

More from ajoy21

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxajoy21
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxajoy21
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxajoy21
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxajoy21
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxajoy21
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxajoy21
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxajoy21
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxajoy21
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxajoy21
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxajoy21
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxajoy21
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxajoy21
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxajoy21
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxajoy21
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxajoy21
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxajoy21
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxajoy21
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxajoy21
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxajoy21
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxajoy21
 

More from ajoy21 (20)

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docx
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docx
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docx
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docx
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docx
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docx
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docx
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docx
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docx
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docx
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docx
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docx
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docx
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
 

Recently uploaded

Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 

Recently uploaded (20)

Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

Work on Static methods OBJECTIVES -continue to practice to write the .docx

  • 1. Work on Static methods OBJECTIVES -continue to practice to write the code for the data type class -Learn what is static members in data type class and how to write static methods - Learn how to access static members of data type class from main() Provide the application that helps users to calculate the area of the following list of shapes. Square Rectangle Triangle Circle Trapezoid Rhombus Kite Parallelogram For each shape, you can ask for all necessary information of the selected shape to calculate its area from the keyboard. The result should be displayed in the following format, for example with selected shape is Rectangle -Manage the menu with the do., while loop to redisplayed the menu after finishing one shape -How to write the switch statement -How to format the output in columns and with 2 decimal digits -How to create the static method in data type class -How to access static method of data type class from main() -The formula to calculate the area of all above shapes - You have to provide the pseudo code of main() at the top of driver class or in the word document with party -Create a project named SU2016LAB6_PART2_YourLastName then add two classes in -Class SU2016LAB6_ShapeArea_yourLastName that includes all the static methods that receive the information input from main(), calculate the area of required shapes and return its area. -Driver class SU2016LAB6_AccessStaticMethod_yourLastName: this class include main() where you can provide the menu to allow users to select the shapes to calculate the area. For each shape, ask for and read the necessary information to calculate the area from the keyboard, then call the static method of class SU2016LAB6_ShapeArea_yourLastName to pass the information in to get the area. After that, display the result as requested format
  • 2. Solution #include <iostream> #include <conio.h> #include <math.h> using namespace std; class Shape{ //shape class public: virtual double area(); }; class Rectangle : public Shape {//rectangle class private: double width, length; //sides public: Rectangle(double width, double length) { this->width = width; this->length = length; } double area() { // A = w * l return width * length; }
  • 3. }; class Rhombus: public Shape{//rhombus class private: double width, length; //2 diagonals public: Rhombus(double width, double length) { this->width = width; this->length = length; } double area() { return 1/2*width * length; } }; class Kite:public Shape{//kite class private: double width, length; //2 diagonals public: Kite(double width, double length) { this->width = width; this->length = length; } double area() { return 1/2*width * length; } };
  • 4. class Parallelogram:public Shape {//parallelogram class private:double width, length; //sides public: Parallelogram(double width, double length) { this->width = width; this->length = length; } double area() { return width * length; } }; class Circle:public Shape {//circle class private: double radius; public: Circle(double radius) { this->radius = radius; } double area() { // A = p r^2 return 22/7 * radius*radius; } }; class Square:public Shape{//square class private: double side; public:
  • 5. Square(double side) { this->side = side; } double area() { return side*side; } }; class Triangle:public Shape{//triangle class private: double a, b, c; // sides public: Triangle(double a, double b, double c) { this->a = a; this->b = b; this->c = c; } double area() { // Heron's formula: // A = SquareRoot(s * (s - a) * (s - b) * (s - c)) // where s = (a + b + c) / 2, or 1/2 of the perimeter of the triangle double s = (a + b + c) / 2; return sqrt(s * (s - a) * (s - b) * (s - c)); } }; class Trapezoid:public Shape{//trapezoid class
  • 6. private: double a, b, c; // sides public: Trapezoid(double a, double b, double c) { this->a = a; this->b = b; this->c = c; } double area() { return 1/2*(a+b)*c; } }; int main() { // Square test double side; cout<<"Enter the side"<<endl; cin>>side; Shape square = Square(side); cout<<"Shape : Square "<<"side = "<<side<<" Area = " << square.area()<< " "; // Rectangle test double width,length; cout<<"Enter the width and length"<<endl; cin>>width>>length;
  • 7. Shape rectangle = Rectangle(width, length); cout<<"Shape : Rectangle "<< "Width = "<<width<<" Length = "<< length << " Area = " << rectangle.area()<< " "; // Triangle test double a, b, c; cout<<"enter the sides of th triangle"<<endl; cin>>a>>b>>c; Shape triangle = Triangle(a,b,c); cout<<"Shape : Triangle " << "Side1 = "<<a <<" "<< "Side2 = " << b<<" Side3 = "<< c << " Area = " << triangle.area()<< " "; // Circle test double radius; cout<<"Enter the radius"<<endl; cin>>radius; Shape circle = Circle(radius); cout<<"Shape : Circle " << "Radius = "<<radius << " Area = " << circle.area()<< " "; // Trapezoid test double a1, b1, c1; cout<<"enter the sides of th trapezoid"<<endl; cin>>a1>>b1>>c1;
  • 8. Shape trapezoid =Trapezoid(a,b,c); cout<<"Shape : Trapezoid "<< "Base1 = "<<a1 <<" Base2 = "<< b1<<" Height = "<< c1 <<" Area = " <<trapezoid.area()<< " "; // Rhombus test double diag1,diag2; cout<<"Enter the diagonals"<<endl; cin>>diag1>>diag2; Shape rhombus =Rhombus(diag1, diag2); cout<<"Shape : Rhombus " << "diagonal1 = "<<diag1<<" diagonal2 = " << diag2 << " Area = "<< rhombus.area()<< " "; // Kite test double diag3,diag4; cout<<"Enter the diagonals"<<endl; cin>>diag1>>diag2; Shape kite =Kite(diag3, diag4); cout<<"Shape : Kite "<< "diagonal1 = "<<diag3<<" diagonal2 = " << diag4 <<" Area = "<< kite.area()<< " "; // Parallelogram test double width3, length3;
  • 9. cout<<"Enter the width and length"<<endl; cin>>width3>>length3; Shape parallelogram = Parallelogram(width3, length3); cout<<"Shape : parallelogram " << "Base = "<<width3 <<" Length = "<< length3 <<" Area = " << parallelogram.area()<< " "; return 0; }