Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Computer science questions for each picture 1. Create a new C++ class called Point // point.h file ifndef POINT H define POINT H class Point

Computer science questions for each picture image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
1. Create a new C++ class called Point // point.h file ifndef POINT H define POINT H class Point ( tendif point.cpp tile *include "point . h" 1.1. What is the difference and relationship between a h and .cpp file? 1.2. What is a header guard? Why do we need header guards? 1.3. Can we create a new Point object given the above files? 2. Add private class variables x and y. Add public getter and setter functions for these variables // point.h file # i fndet POINT H Idefine POINT H class Point public int getx const void setx (int x) int getY) const void setY (int newy) private int x int yi tendif // point.cpp Eile include "point.h" int Point::getX0 const return x void Point::setx (int x) Point::xxi int Point:sgetYO const return y void Point::sety (int newy) 2.1. What is the difference between public and private parts of a class? 2.2. Why do some classes have const after the function name? 2.3. Why do functions have Point: as part of their name in the cpp class? 2.4. Compare setx and set functions showing two different ways of implementing a similar function. How are they different? 3. Add a new function, testPoint, in main.cpp that creates a Point object, sets x and y values and then prints them main.cpp include ciostream> include "point-h" using nameapace atd void testPoint) Point p p.setx (10) p.sety (20) cout / constructor using initialization Iist point : :Pointiintx, nt y} { Point: :x-x Point::y-y: else throw invalid argument ("x and y have to be 0 or a positive number" void Point::setx (int x) ( if (x -0) Point::i else throw nvalid argument ("x has to be 0 o a positive number") void Point::sety (int newy) (ewy0) this-y -newy else throw invalid argument("y has to be 0 ox a positive numbe") 6.1 How as the 2-parameter constructor modified? 6.2. Do we need extra parentheses for "x-and"y" in the if statement of the 2-parameter constructor? Explain 6.3. setx and setY access the class variables x and y in slightly different way Compare how the class variable is accessed in both functions? 7. Implement a toString function in point class so that we can print Point objects more easily. Modify testPointConstructor to use the new toString function point.h file i frdef POINT H define POINTH include std: istring tostring)const point.cpp file include Include include"point.h" string Point::tostring) const f ostringstzeam out out y tostring )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books