Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
For this assignment you will be building on the Fraction class you began last week. All the requirements from that class are still in force. You'll be making five major changes to the class.
- Delete your set() function. Add two constructors, a default constructor (a constructor that takes no parameters) and a parameterized constructor (a constructor that takes parameters). The default constructor assigns the value 0 to the Fraction. In the parameterized constructor, the first parameter will represent the initial numerator of the Fraction, and the second parameter will represent the initial denominator of the Fraction.
Since Fractions cannot have denominators of 0, the default constructor should assign 0 to the numerator and 1 to the denominator. Also, the parameterized constructor should check to make sure that the second parameter is not a 0 by using the statement "assert(denominatorParameter != 0);". To use the assert() function you'll also need to #include <cassert>. (Note, I don't expect the variable to be named "denominatorParameter," that's just my placeholder for the example.)
assert() is not the best way to handle this, but it will have to do until we study exception handling. - Add the const keyword to your class wherever appropriate (and also make sure to pass objects by reference -- see lesson 15.9). Your class may still work correctly even if you don't do this correctly, so this will require extra care!!
- Add a private "simplify()" function to your class and call it from the appropriate member functions. The best way to do this is to make the function a void function with no parameters that reduces the calling object.
Expert Solution
arrow_forward
Step 1 Introduction
In C++ which refers to an object-oriented programming language which gives a clear structure to programs and also which allows code to be reused, lowering development costs. C++ which is portable and that can be used to develop applications that can be adapted to multiple platforms. C++ which is also a general-purpose programming language
Step by stepSolved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.Similar questions
- Deeper Class Design - the Square Class In this section, your job will be to write a new class that will adhere to the methods and data outlined in the “members” section below (said another way, your classes will implement a specific set of functions (called an interface) that we’ll describe contractually, ahead of time). These classes will all be shapes, with actions (methods) that are appropriate to shape objects, such as “getArea()”, or “draw()”. First we build a Square class that contains the following data and methods listed below, and then later, we will copy it to quickly make a Circle class. Note: when considering each data item below, think about what type of data would best represent the concept we’re trying to model in our software. For example, all shapes will have a coordinate pair indicating their location in a Cartesian coordinate system. This x and y pair may be modeled as ints or floats, and you might choose between the two depending on what the client application will…arrow_forwardClass Triangle ï A Triangle will have 3 sides. The class will be able to keep track of the number of Triangle objects created. It will also hold the total of the perimeters of all the Triangle objects created. ï It will allow a client to create a Triangle, passing in integer values for the three sides into the Triangle constructor. If the values for the sides that are passed in do not represent a valid Triangle (read below for the requirements for a Triangle to be valid) , then all sides will be set to a value of 1. The constructor should add 1 to the count of the number of Triangles created. The constructor should call a method to calculate the perimeter and then add the perimeter for that object to an accumulator. In addition to the constructor, the Triangle class must have the following methods that return a boolean value: isRight () - see note 1 below regarding Acute triangles. isAcute() - see note 1 below regarding Acute triangles. isObtuse() - see note…arrow_forwardLet’s assume you are creating a game where multiple players are involved. You will create a Player class that will allow you to later create Player objects. Each player will need a name, a health level, a super power, and number of lives remaining. In your Player class we need the following: Four private data members: name (a String) health (an int) power (a String) lives (an int) Three Constructors: A constructor that has no parameters and sets name to “No Name”, health to 100, power to “Nothing”, and lives to 3.A constructor that takes in two parameters – a String for the name and a String for the power. The health variable should be set to 100 and the lives variable should be set to 3 by default. A constructor that takes in all four parameters and sets them. Accessors and Modifiers (8 total): Create an accessor/getter for all four private data members. Create a modifier/setter for all four private data members. toString() method Create a toString() method that neatly displays the…arrow_forward
- Create a Puppy class with private property color and both a getter and a setter for that property called getColor and setColor. The constructor should take a parameter to initialize the private property. 1arrow_forwardWrite a class called Alien. The Alien class must have one field of type String called name, one of type String called planet and one field of type boolean called humanoid. Write one constructor that takes three parameters to initialise all of these fields. The parameters must be passed in the order name, planet and humanoid status. IntelliJ hint (this won't be in the real test): put your cursor after the last field; right-click, choose Generate, choose Constructor, select the fields that are set via parameters and click Ok. Check that the constructor is correct. Write a getter method for each field. IntelliJ hint (this won't be in the real test): put your cursor after the closing curly bracket of the constructor; right click, choose Generate, choose Getter, select all of the fields; click Ok. Check that the you have three getters. Do not write setters methods. Write a method called getDetails that will return the values of the fields in one of the following two formats. For example,…arrow_forwardIs there a different way of doing this problem? Question: Create a class AccessPoint with the following attributes: x - a double representing the x coordinate y - a double representing the y coordinate range - an integer representing the coverage radius status - On or Off Add constructors. The default constructor should create an access point object at position (0.0, 0.0), coverage radius 0, and Off. Add accessor and mutator functions: getX, getY, getRange, getStatus, setX, setY, setRange and setStatus. Also, add a set function that sets the location coordinates and the range. Add the following member functions: move and coverageArea. Add a function overlap that checks if two access points overlap their coverage and returns true if they overlap. Add a function signalStrength that returns the wireless signal strength as a percentage. The signal strength decreases as one moves away from the access point location. Test your class by writing a main function that creates five access…arrow_forward
- 1. for this question do not write the code just explain how you would Create a class called Elevator that can be moved between floors in an N-storey building. Elevator uses a constructor to initialize the number of floors (N) in the building when the object is instantiated. Elevator also has a default constructor that creates a five- (5) storey building. The Elevator class has a termination condition that requires the elevator to be moved to the main (i.e., first) floor when the object is cleaned up. Write a finalize() method that satisfies this termination condition and verifies the condition by printing a message to the output, Elevator ending: elevator returned to the first floor. In main(), test at least five (5) possible scenarios that can occur when Elevator is used in a building with many floors (e.g., create, move from one floor to another, etc.). Hint: Termination occurs when the instance is set to null. You may wish to investigate “garbage collection” for this exercise.arrow_forwardJave assignment: Create a class called Player that has the following attributes: Player Health - Integer Intelligence - Integer Dexterity - Integer Strength - Integer Stamina - Integer Player() Player(Health, Intelligence, Dexterity, Strength, Stamina) getHealth() - Integer setHealth(Integer) - Void getIntelligence() - Integer setIntelligence(Integer) - Void getDexterity() - Integer setDexterity(Integer) - Void getStrength() - Integer setStrength(Integer) - Void getStamina() - Integer setStamina(Integer) - Void toString() - String compareTo(Player) - Integer equals(Player) - Boolean Notes: All attributes should not be allowed to be set below 0.arrow_forward5. class definition for GameEnemy Next, we want to start making enemies for our upcoming video game, so we will define a class called GameEnemy. Every GameEnemy will have a name, an x location, a y location, and a number of hit points (which must be a non- negative integer ). The_init__ method for GameEnemy will take all of these parameters (in that order) and store them on the object. GameEnemy also needs a method called healthbar, which will allow us to show that enemy's health bar in the game. It returns the enemy's name followed by a number of asterisks to show how many hit points it has left. The exact format is shown below. Sample runs should look like: >>> enemy = GameEnemy ("TODD", 100, 200, 5) >>> enemy.healthbar() TODD: ****** >>> enemy-% ence 100 >>> enemy-y 200 If vou havo qu octionaarrow_forward
- Help me solve this in Java, don't make it to complicated.arrow_forwardWritten in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forwardFor this assignment you will be building on your Fraction class. However, the changes will be significant, so I would recommend starting from scratch and using your previous version as a resource when appropriate. For this assignment, we will correctly handle Fractions that are negative, improper (larger numerator than denominator), or whole numbers (denominator of 1). Your class should support the following operations on Fraction objects: Construction of a Fraction from two, one, or zero integer arguments. If two arguments, they are assumed to be the numerator and denominator, just one is assumed to be a whole number, and zero arguments creates a zero Fraction. Use default parameters so that you only need a single function to implement all three of these constructors.You should check to make sure that the denominator is not set to 0. The easiest way to do this is to use an assert statement: assert(inDenominator != 0); You can put this statement at the top of your constructor. Note…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY