SlideShare uma empresa Scribd logo
1 de 3
C++
Define a class called Cylinder with two data members: double radius and double height. The
definition should include all the set and get functions. The class should also have two member
functions. One is for calculating and returning the volume of the cylinder and one is for
calculating and returning the surface area of the cylinder. The class Cylinder should also have a
constructor. Define a class called Circle with one data member: double radius. The class Circle
should have all the set and get function, constructor, and a member function that calculates and
returns the area of the circle. Write a complete program that is testing above two classes.
Solution
#include <iostream>
#include <string>
using namespace std;
class Cylinder
{
private:
double radius;
double height;
public:
// Constructors
Cylinder();
Cylinder(double r, double h){
radius = r;
height = h;
}
// Accessors
double getRadius(){
return radius;
}
double getHeight(){
return height;
}
void setRadius(double r){
radius = r;
}
void setHeight(double h){
height = h;
}
double getVolume(){
return 3.14 * radius * radius * height;
}
double getArea(){
return getVolume() * 2 * 3.14 * radius * radius;
}
};
class Circle{
private:
double radius;
public:
Circle(); //Constructor
Circle(double r){
radius = r;
}
void setRadius(int r){
if (r >= 0)
radius = r;
else {
cout << "Invalid radius "<< endl;
exit(EXIT_FAILURE);
}
}
int getRadius(){
return radius;
}
double getArea() const{
return 3.14 * radius * radius;
}
};
int main()
{
Cylinder CylinderOne(10.0, 10.0);
cout << "Cylinder Radius: " << CylinderOne.getRadius() << endl;
cout << "Cylinder Height: " << CylinderOne.getHeight() << endl;
cout << "Cylinder area: " << CylinderOne.getArea() << endl;
cout << "Cylinder volume: " << CylinderOne.getVolume() << endl;
Circle CircleOne(10.0);
cout << "Circle Radius: " << CircleOne.getRadius() << endl;
cout << "Circle area: " << CircleOne.getArea() << endl;
}

Mais conteúdo relacionado

Semelhante a C++ Define a class called Cylinder with two data members- double radiu.docx

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialskailash454
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.pptDeepVala5
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritancezindadili
 
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
 
Chapter 13 introduction to classes
Chapter 13 introduction to classesChapter 13 introduction to classes
Chapter 13 introduction to classesrsnyder3601
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#ANURAG SINGH
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfANJALIENTERPRISES1
 
Chapter19 constructor-and-destructor
Chapter19 constructor-and-destructorChapter19 constructor-and-destructor
Chapter19 constructor-and-destructorDeepak Singh
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Kasun Ranga Wijeweera
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined MethodPRN USM
 
Lecture-03 _Java Classes_from FAST-NUCES
Lecture-03 _Java Classes_from FAST-NUCESLecture-03 _Java Classes_from FAST-NUCES
Lecture-03 _Java Classes_from FAST-NUCESUzairSaeed18
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsRai University
 
Write a class Runner that contains the following data members.docx
Write a class Runner that contains the following data members.docxWrite a class Runner that contains the following data members.docx
Write a class Runner that contains the following data members.docxzahid javed
 

Semelhante a C++ Define a class called Cylinder with two data members- double radiu.docx (20)

C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
UNIT I (1).ppt
UNIT I (1).pptUNIT I (1).ppt
UNIT I (1).ppt
 
UNIT I (1).ppt
UNIT I (1).pptUNIT I (1).ppt
UNIT I (1).ppt
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.ppt
 
Hierarchical inheritance
Hierarchical inheritanceHierarchical inheritance
Hierarchical inheritance
 
Oo ps
Oo psOo ps
Oo ps
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
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
 
C++ classes
C++ classesC++ classes
C++ classes
 
Bc0037
Bc0037Bc0037
Bc0037
 
Chapter 13 introduction to classes
Chapter 13 introduction to classesChapter 13 introduction to classes
Chapter 13 introduction to classes
 
Oops concept in c#
Oops concept in c#Oops concept in c#
Oops concept in c#
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
 
Chapter19 constructor-and-destructor
Chapter19 constructor-and-destructorChapter19 constructor-and-destructor
Chapter19 constructor-and-destructor
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 
Lecture-03 _Java Classes_from FAST-NUCES
Lecture-03 _Java Classes_from FAST-NUCESLecture-03 _Java Classes_from FAST-NUCES
Lecture-03 _Java Classes_from FAST-NUCES
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
Write a class Runner that contains the following data members.docx
Write a class Runner that contains the following data members.docxWrite a class Runner that contains the following data members.docx
Write a class Runner that contains the following data members.docx
 

Mais de gilliandunce53776

Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxBullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxgilliandunce53776
 
c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxgilliandunce53776
 
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxBusiness Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxgilliandunce53776
 
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxBrief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxgilliandunce53776
 
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxBriefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxgilliandunce53776
 
Brief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxBrief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxgilliandunce53776
 
Both Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxBoth Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxgilliandunce53776
 
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxBrand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxgilliandunce53776
 
Betty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxBetty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxgilliandunce53776
 
Beyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxBeyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxgilliandunce53776
 
Below is accounting information for Cascade Company for 2013- What we.docx
Below is accounting information for Cascade Company for 2013-  What we.docxBelow is accounting information for Cascade Company for 2013-  What we.docx
Below is accounting information for Cascade Company for 2013- What we.docxgilliandunce53776
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxgilliandunce53776
 
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxcaiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxgilliandunce53776
 
C++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxC++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxgilliandunce53776
 
C++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docxC++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docxgilliandunce53776
 

Mais de gilliandunce53776 (15)

Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxBullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
 
c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docx
 
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxBusiness Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
 
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxBrief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
 
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxBriefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
 
Brief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxBrief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docx
 
Both Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxBoth Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docx
 
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxBrand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
 
Betty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxBetty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docx
 
Beyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxBeyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docx
 
Below is accounting information for Cascade Company for 2013- What we.docx
Below is accounting information for Cascade Company for 2013-  What we.docxBelow is accounting information for Cascade Company for 2013-  What we.docx
Below is accounting information for Cascade Company for 2013- What we.docx
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
 
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxcaiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
 
C++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxC++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docx
 
C++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docxC++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docx
 

Último

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Último (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

C++ Define a class called Cylinder with two data members- double radiu.docx

  • 1. C++ Define a class called Cylinder with two data members: double radius and double height. The definition should include all the set and get functions. The class should also have two member functions. One is for calculating and returning the volume of the cylinder and one is for calculating and returning the surface area of the cylinder. The class Cylinder should also have a constructor. Define a class called Circle with one data member: double radius. The class Circle should have all the set and get function, constructor, and a member function that calculates and returns the area of the circle. Write a complete program that is testing above two classes. Solution #include <iostream> #include <string> using namespace std; class Cylinder { private: double radius; double height; public: // Constructors Cylinder(); Cylinder(double r, double h){ radius = r; height = h; } // Accessors double getRadius(){ return radius; }
  • 2. double getHeight(){ return height; } void setRadius(double r){ radius = r; } void setHeight(double h){ height = h; } double getVolume(){ return 3.14 * radius * radius * height; } double getArea(){ return getVolume() * 2 * 3.14 * radius * radius; } }; class Circle{ private: double radius; public: Circle(); //Constructor Circle(double r){ radius = r; } void setRadius(int r){ if (r >= 0) radius = r; else { cout << "Invalid radius "<< endl; exit(EXIT_FAILURE); } } int getRadius(){
  • 3. return radius; } double getArea() const{ return 3.14 * radius * radius; } }; int main() { Cylinder CylinderOne(10.0, 10.0); cout << "Cylinder Radius: " << CylinderOne.getRadius() << endl; cout << "Cylinder Height: " << CylinderOne.getHeight() << endl; cout << "Cylinder area: " << CylinderOne.getArea() << endl; cout << "Cylinder volume: " << CylinderOne.getVolume() << endl; Circle CircleOne(10.0); cout << "Circle Radius: " << CircleOne.getRadius() << endl; cout << "Circle area: " << CircleOne.getArea() << endl; }