Writing a class

Assignment Help Programming Languages
Reference no: EM13708

Problem: Build a class for a type called Fraction. 

This class is used to show a ration of two integers.  Include mutator functions that allow the user to set the numerator and the denominator.  Also, add a member function that returns the value of the numerator divided by the denominator as a double.  Include another member function that outputs the value of the fraction reduced to the lowest terms. 

For illustration, instead of outputting 20/60 the function should output 1/3.  This requires finding the greatest common divisor for the numerator and denominator, and then dividing both by that number.  Embed your class in a test program.  
 
For example, Write a test program that asks the user for an integer numerator and integer denominator, print the real number from evaluating the fraction, and then print the fraction reduced to its lowest terms.

Enter a numerator: 20
Enter a denominator: 60
The result of your fraction is .333333.
Your fraction in lowest terms is 1 / 3.
 
Prepare a Temperature class that internally stores a temperature in degrees Kelvin. 

Create functions named setTempKelvin, setTempFahrenheit, and setTempCelsius that take an input temperature in the specified temperature scale, convert the temperature to Kelvin, and store that temperature in the class member variable.  Also, create functions that return the stored temperature in degrees Kelvin, Fahrenheit, or Celsius. 

Write a main function to test your class.  Use the equations shown next to convert between the three temperatures scales.

Kelvin = Celsius + 273.15

Celsius = (5.0 / 9) * (Fahrenheit - 32)
 
For example, you might ask the user which kind of temperature he/she wants to enter, and then output the temperature in Kelvin, Fahrenheit, and Celsius.

Which kind of temperature would you like to enter (Kelvin (1), Fahrenheit(2), or Celsius(3))? 1

Enter your temperature: 20.0

Your temperature in Kelvin is 20.

Your temperature in Celsius is -253.15.

Your temperature in Fahrenheit is -423.67.

Reference no: EM13708

Questions Cloud

Pulse width modulator : A pulse width modulation (PWM) circuit works by varying the duty cycle of the square wave while keeping the period fixed.
Design a base class shape with virtual functions : Design a base class shape with virtual functions
Develop a dynamic website open university : Develop a dynamic website Open University
Traffic light controller : The schematic of the traffic light controller
Writing a class : Build a class for a type called Fraction
Evaluate the expected value of the total number of sales : Evaluate the expected value of the total number of sales
Blackbody : Questions on blackbody, Infra-Red Detectors & Optic Lens and Digital Image.
Compute the entry in the rijndaels-box : Compute the entry in the RijndaelS-box
Impact of electron energy : Briefly discuss the impact of electron energy, electron current and target on the Bremsstrahlung generated.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd