SlideShare une entreprise Scribd logo
1  sur  4
Do the following with class Shape: a. Add prototypes for all required methods and operators for
the class (the Point class is the one from problem one above).
1///////////////////////////////////////////////////////////////////////////////////////////////
template <class T>
class Point
{
private:
TÂ Â X;
TÂ Â Y;
public:
Point() {
X=0;
Y=0;
}
T getX() {
return X;
}
void setX(T x) {
X = x;
}
T getY() {
return Y;
}
void setY(T y) {
Y = y;
}
Point operator+(Point a, Point b) {
Point r;
r.X = a.X+b.X;
r.Y = a.Y+b.Y;
return r;
}
};
2//////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T>
class Shape
{
public:
private:
Point<T> Origin;
};
Solution
Along with solution i am also correcting the operator + function.
The operator + is within the class so it will accept one argument only. Two argument is required
in case of friend functions.
#include <iostream>
using namespace std;
template <class T>
class Point
{
private:
T X;
T Y;
public:
Point() {
X=0;
Y=0;
}
T getX() {
return X;
}
void setX(T x) {
X = x;
}
T getY() {
return Y;
}
void setY(T y) {
Y = y;
}
Point operator + (Point<T> a) {
Point<T> r;
r.X = a.X+this.X;
r.Y = a.Y+this.Y;
return r;
}
};
template <class T>
class Shape
{
public:
T area_rectangle(T ,T ); // prototype to calculate area of rectangle
T area_circle(T ); // prototype to calculate area of circle
Point<T> operator * (Point<T> );// prototype for multiplication used in area of rectangle
Point<T> operator / (Point<T> );// prototype for division used in area of circle(22/7 as pie)
private:
Point<T> Origin;
};
Do the following with class Shape- a- Add prototypes for all required (1).docx

Contenu connexe

Similaire à Do the following with class Shape- a- Add prototypes for all required (1).docx

Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
aromanets
 
李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义
yiditushe
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8
ecomputernotes
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
PRN USM
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
bunnykhan
 
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
 
CodeFest 2013. Rauschmayer A. — An overview of ECMAScript 6, the next version...
CodeFest 2013. Rauschmayer A. — An overview of ECMAScript 6, the next version...CodeFest 2013. Rauschmayer A. — An overview of ECMAScript 6, the next version...
CodeFest 2013. Rauschmayer A. — An overview of ECMAScript 6, the next version...
CodeFest
 
1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf
forwardcom41
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
Palak Sanghani
 
Take Note These questions requires diagrams.Scenario Sweetbriar .pdf
Take Note These questions requires diagrams.Scenario Sweetbriar .pdfTake Note These questions requires diagrams.Scenario Sweetbriar .pdf
Take Note These questions requires diagrams.Scenario Sweetbriar .pdf
eyeonsecuritysystems
 

Similaire à Do the following with class Shape- a- Add prototypes for all required (1).docx (20)

Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Chap08
Chap08Chap08
Chap08
 
李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义
 
computer notes - Data Structures - 8
computer notes - Data Structures - 8computer notes - Data Structures - 8
computer notes - Data Structures - 8
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
 
Multiple file programs, inheritance, templates
Multiple file programs, inheritance, templatesMultiple file programs, inheritance, templates
Multiple file programs, inheritance, templates
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
CodeFest 2013. Rauschmayer A. — An overview of ECMAScript 6, the next version...
CodeFest 2013. Rauschmayer A. — An overview of ECMAScript 6, the next version...CodeFest 2013. Rauschmayer A. — An overview of ECMAScript 6, the next version...
CodeFest 2013. Rauschmayer A. — An overview of ECMAScript 6, the next version...
 
Csphtp1 10
Csphtp1 10Csphtp1 10
Csphtp1 10
 
3433 Ch10 Ppt
3433 Ch10 Ppt3433 Ch10 Ppt
3433 Ch10 Ppt
 
Templates presentation
Templates presentationTemplates presentation
Templates presentation
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09
 
1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf1. Suppose you want to implement an ADT in which you can insert valu.pdf
1. Suppose you want to implement an ADT in which you can insert valu.pdf
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
PPT
PPTPPT
PPT
 
Take Note These questions requires diagrams.Scenario Sweetbriar .pdf
Take Note These questions requires diagrams.Scenario Sweetbriar .pdfTake Note These questions requires diagrams.Scenario Sweetbriar .pdf
Take Note These questions requires diagrams.Scenario Sweetbriar .pdf
 

Plus de rtodd615

Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docxDiscuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
rtodd615
 
Discuss the differences between a form and a report- What characterist.docx
Discuss the differences between a form and a report- What characterist.docxDiscuss the differences between a form and a report- What characterist.docx
Discuss the differences between a form and a report- What characterist.docx
rtodd615
 
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docxDQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
rtodd615
 
Discuss in scholarly detail implications of any considerations that sh.docx
Discuss in scholarly detail implications of any considerations that sh.docxDiscuss in scholarly detail implications of any considerations that sh.docx
Discuss in scholarly detail implications of any considerations that sh.docx
rtodd615
 
Does adding debt increase or decrease the flexibility of a healthcare.docx
Does adding debt increase or decrease the flexibility of a healthcare.docxDoes adding debt increase or decrease the flexibility of a healthcare.docx
Does adding debt increase or decrease the flexibility of a healthcare.docx
rtodd615
 
Discuss the difference between Financial Accounting and Managerial Acc (1).docx
Discuss the difference between Financial Accounting and Managerial Acc (1).docxDiscuss the difference between Financial Accounting and Managerial Acc (1).docx
Discuss the difference between Financial Accounting and Managerial Acc (1).docx
rtodd615
 
Distinguish between individual barriers and organizational barriers to.docx
Distinguish between individual barriers and organizational barriers to.docxDistinguish between individual barriers and organizational barriers to.docx
Distinguish between individual barriers and organizational barriers to.docx
rtodd615
 
Discussion Topic 1- Internal control consists of the policies and proc.docx
Discussion Topic 1- Internal control consists of the policies and proc.docxDiscussion Topic 1- Internal control consists of the policies and proc.docx
Discussion Topic 1- Internal control consists of the policies and proc.docx
rtodd615
 
Discuss the tools and technologies for collaboration and teamwork that.docx
Discuss the tools and technologies for collaboration and teamwork that.docxDiscuss the tools and technologies for collaboration and teamwork that.docx
Discuss the tools and technologies for collaboration and teamwork that.docx
rtodd615
 
discuss the role of nanotechnology in today-'s information age-Solutio.docx
discuss the role of nanotechnology in today-'s information age-Solutio.docxdiscuss the role of nanotechnology in today-'s information age-Solutio.docx
discuss the role of nanotechnology in today-'s information age-Solutio.docx
rtodd615
 
Discuss the reasons for the growing interest in and availability of hi.docx
Discuss the reasons for the growing interest in and availability of hi.docxDiscuss the reasons for the growing interest in and availability of hi.docx
Discuss the reasons for the growing interest in and availability of hi.docx
rtodd615
 
Discuss the nature of Greek theater and the purpose it served in Ancie.docx
Discuss the nature of Greek theater and the purpose it served in Ancie.docxDiscuss the nature of Greek theater and the purpose it served in Ancie.docx
Discuss the nature of Greek theater and the purpose it served in Ancie.docx
rtodd615
 
Discuss the impact of a strong culture on organization and managersSol.docx
Discuss the impact of a strong culture on organization and managersSol.docxDiscuss the impact of a strong culture on organization and managersSol.docx
Discuss the impact of a strong culture on organization and managersSol.docx
rtodd615
 
Discuss the advantage and disadvantage of supporting links to files th.docx
Discuss the advantage and disadvantage of supporting links to files th.docxDiscuss the advantage and disadvantage of supporting links to files th.docx
Discuss the advantage and disadvantage of supporting links to files th.docx
rtodd615
 
Discuss how engineers and risk experts view and deal with risks- (Appr.docx
Discuss how engineers and risk experts view and deal with risks- (Appr.docxDiscuss how engineers and risk experts view and deal with risks- (Appr.docx
Discuss how engineers and risk experts view and deal with risks- (Appr.docx
rtodd615
 
Discuss how complementary social- managerial- and organizational asset.docx
Discuss how complementary social- managerial- and organizational asset.docxDiscuss how complementary social- managerial- and organizational asset.docx
Discuss how complementary social- managerial- and organizational asset.docx
rtodd615
 
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docxdifference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
rtodd615
 
Effective managers stay abreast of current HR topics- Some relevant is.docx
Effective managers stay abreast of current HR topics- Some relevant is.docxEffective managers stay abreast of current HR topics- Some relevant is.docx
Effective managers stay abreast of current HR topics- Some relevant is.docx
rtodd615
 
effective managers stay abreast of current HR topics- Some relevant is (1).docx
effective managers stay abreast of current HR topics- Some relevant is (1).docxeffective managers stay abreast of current HR topics- Some relevant is (1).docx
effective managers stay abreast of current HR topics- Some relevant is (1).docx
rtodd615
 

Plus de rtodd615 (20)

Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docxDiscuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
 
Discuss the differences between a form and a report- What characterist.docx
Discuss the differences between a form and a report- What characterist.docxDiscuss the differences between a form and a report- What characterist.docx
Discuss the differences between a form and a report- What characterist.docx
 
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docxDQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
 
Discuss in scholarly detail implications of any considerations that sh.docx
Discuss in scholarly detail implications of any considerations that sh.docxDiscuss in scholarly detail implications of any considerations that sh.docx
Discuss in scholarly detail implications of any considerations that sh.docx
 
Does adding debt increase or decrease the flexibility of a healthcare.docx
Does adding debt increase or decrease the flexibility of a healthcare.docxDoes adding debt increase or decrease the flexibility of a healthcare.docx
Does adding debt increase or decrease the flexibility of a healthcare.docx
 
Discuss the difference between Financial Accounting and Managerial Acc (1).docx
Discuss the difference between Financial Accounting and Managerial Acc (1).docxDiscuss the difference between Financial Accounting and Managerial Acc (1).docx
Discuss the difference between Financial Accounting and Managerial Acc (1).docx
 
Distinguish between individual barriers and organizational barriers to.docx
Distinguish between individual barriers and organizational barriers to.docxDistinguish between individual barriers and organizational barriers to.docx
Distinguish between individual barriers and organizational barriers to.docx
 
Discussion Topic 1- Internal control consists of the policies and proc.docx
Discussion Topic 1- Internal control consists of the policies and proc.docxDiscussion Topic 1- Internal control consists of the policies and proc.docx
Discussion Topic 1- Internal control consists of the policies and proc.docx
 
Discuss the tools and technologies for collaboration and teamwork that.docx
Discuss the tools and technologies for collaboration and teamwork that.docxDiscuss the tools and technologies for collaboration and teamwork that.docx
Discuss the tools and technologies for collaboration and teamwork that.docx
 
Discuss the statement of cash flows Values Limitations This relates to.docx
Discuss the statement of cash flows Values Limitations This relates to.docxDiscuss the statement of cash flows Values Limitations This relates to.docx
Discuss the statement of cash flows Values Limitations This relates to.docx
 
discuss the role of nanotechnology in today-'s information age-Solutio.docx
discuss the role of nanotechnology in today-'s information age-Solutio.docxdiscuss the role of nanotechnology in today-'s information age-Solutio.docx
discuss the role of nanotechnology in today-'s information age-Solutio.docx
 
Discuss the reasons for the growing interest in and availability of hi.docx
Discuss the reasons for the growing interest in and availability of hi.docxDiscuss the reasons for the growing interest in and availability of hi.docx
Discuss the reasons for the growing interest in and availability of hi.docx
 
Discuss the nature of Greek theater and the purpose it served in Ancie.docx
Discuss the nature of Greek theater and the purpose it served in Ancie.docxDiscuss the nature of Greek theater and the purpose it served in Ancie.docx
Discuss the nature of Greek theater and the purpose it served in Ancie.docx
 
Discuss the impact of a strong culture on organization and managersSol.docx
Discuss the impact of a strong culture on organization and managersSol.docxDiscuss the impact of a strong culture on organization and managersSol.docx
Discuss the impact of a strong culture on organization and managersSol.docx
 
Discuss the advantage and disadvantage of supporting links to files th.docx
Discuss the advantage and disadvantage of supporting links to files th.docxDiscuss the advantage and disadvantage of supporting links to files th.docx
Discuss the advantage and disadvantage of supporting links to files th.docx
 
Discuss how engineers and risk experts view and deal with risks- (Appr.docx
Discuss how engineers and risk experts view and deal with risks- (Appr.docxDiscuss how engineers and risk experts view and deal with risks- (Appr.docx
Discuss how engineers and risk experts view and deal with risks- (Appr.docx
 
Discuss how complementary social- managerial- and organizational asset.docx
Discuss how complementary social- managerial- and organizational asset.docxDiscuss how complementary social- managerial- and organizational asset.docx
Discuss how complementary social- managerial- and organizational asset.docx
 
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docxdifference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
 
Effective managers stay abreast of current HR topics- Some relevant is.docx
Effective managers stay abreast of current HR topics- Some relevant is.docxEffective managers stay abreast of current HR topics- Some relevant is.docx
Effective managers stay abreast of current HR topics- Some relevant is.docx
 
effective managers stay abreast of current HR topics- Some relevant is (1).docx
effective managers stay abreast of current HR topics- Some relevant is (1).docxeffective managers stay abreast of current HR topics- Some relevant is (1).docx
effective managers stay abreast of current HR topics- Some relevant is (1).docx
 

Dernier

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Dernier (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).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
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
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...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

Do the following with class Shape- a- Add prototypes for all required (1).docx

  • 1. Do the following with class Shape: a. Add prototypes for all required methods and operators for the class (the Point class is the one from problem one above). 1/////////////////////////////////////////////////////////////////////////////////////////////// template <class T> class Point { private: TÂ Â X; TÂ Â Y; public: Point() { X=0; Y=0; } T getX() { return X; } void setX(T x) { X = x; } T getY() { return Y; } void setY(T y) { Y = y; }
  • 2. Point operator+(Point a, Point b) { Point r; r.X = a.X+b.X; r.Y = a.Y+b.Y; return r; } }; 2////////////////////////////////////////////////////////////////////////////////////////////////////// template <class T> class Shape { public: private: Point<T> Origin; }; Solution Along with solution i am also correcting the operator + function. The operator + is within the class so it will accept one argument only. Two argument is required in case of friend functions. #include <iostream> using namespace std; template <class T> class Point {
  • 3. private: T X; T Y; public: Point() { X=0; Y=0; } T getX() { return X; } void setX(T x) { X = x; } T getY() { return Y; } void setY(T y) { Y = y; } Point operator + (Point<T> a) { Point<T> r; r.X = a.X+this.X; r.Y = a.Y+this.Y; return r; } }; template <class T> class Shape { public: T area_rectangle(T ,T ); // prototype to calculate area of rectangle T area_circle(T ); // prototype to calculate area of circle Point<T> operator * (Point<T> );// prototype for multiplication used in area of rectangle Point<T> operator / (Point<T> );// prototype for division used in area of circle(22/7 as pie) private: Point<T> Origin; };