C+
Create an application named CarDemo that declares at least two Car objects and demonstrates how they can be incremented using an overloaded ++ operator.
Create a Car class that contains the following properties:
Include two overloaded constructors. One accepts parameters for the model and miles per gallon; the other accepts a model and sets the miles per gallon to 20.
Overload a ++ operator that increases the miles per gallon value by 1. The CarDemo application creates at least one Car using each constructor and displays the Car values both before and after incrementation.
using static System.Console;
class CarDemo
{
static void Main()
{
// Write your main here.
}
public static void Display(string message, Car s)
{
// Write your Display() method here.
}
}
//---------- Car.cs --------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarDemoApplication
{
class Car
{
private string model;
private double mpg;
public Car(string model, double mpg)
{
this.model = model;
this.mpg = mpg;
}
public Car(string model)
{
this.model = model;
this.mpg = 20;
}
public string Model
{
get
{
return model;
}
set
{
model = value;
}
}
public double Mpg
{
get
{
return mpg;
}
set
{
mpg = value;
}
}
public static Car operator ++(Car car)
{
car.Mpg++;
return car;
}
override
public string ToString()
{
return String.Format("{0:-20} : {1,-20:}\n{2:-20} : {3,-20:}",
"Model",this.model,"MPG", this.mpg);
}
}
}
//--------------- CarDemo.cs -------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarDemoApplication
{
class CarDemo
{
static void Main(string[] args)
{
Car one = new Car("Suzuki");
Car two = new Car("BMW", 100);
Display("Car One Before Increment:", one);
one++;
Display("Car One After Increment:", one);
Display("Car Two Before Increment:", two);
two++;
Display("Car Two After Increment:", two);
Console.WriteLine("\nEnter any key to continue");
Console.ReadKey();
}
public static void Display(string message, Car s)
{
Console.WriteLine("\n" + message+"\n");
Console.WriteLine("" + s);
}
}
}
C+ Create an application named CarDemo that declares at least two Car objects and demonstrates how...
C++ Create an application named CarDemo that declares at least two Car objects and demonstrates how they can be incremented using an overloaded ++ operator. Create a Car class that contains the following properties: Model - The car model (as a string) Mpg The car's miles per gallon (as a double) Include two overloaded constructors. One accepts parameters for the model and miles per gallon; the other accepts a model and sets the miles per gallon to 20. Overload a...
Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a method named FillArray to interactively fill the array with any number of values up to 10 or until a sentinel value (999) is entered. If an entry is not an integer, reprompt the user. Call a second method named Statistics that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and...
In java, create a method called getString that will read in Strings as in: Please enter the name of the traveler: david Please enter the destination: rockey mountains Please enter the car model: honda The method is sent: "name of the traveler" or "name of the car" or "destination" The method reads in the String The method returns the String that was read in In the main: String name = getString("the name of the traveler"); Write the method called getString:...
create an application in VISUAL BASIC that calculates a cars gas
mileage. The formula for calculating the miles that a car can
travel per gallon of gas is MPG = Miles/Gallon
In the formula MPG is miles-per-gallon, miles is the number of
miles that can be driven on a full tank of gas, and gallons is the
number of gallons that the tank holds.
The applications form should have TextBox controls that let the
user enter the number of gallons...
CIS247C Week 3 Project Overview The objective of this week is to enhance last week's Vehicle class by making the following changes: • Create a static variable called numVehicles that holds an int and initialize it to zero. This will allow us to count all the Vehicle objects created in the main class. • Add the copy constructor • Increment numVehicles in all of the constructors • Decrement numVehicle in destructor • Add overloaded versions of setYear and setMpg that...
Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...
Use an accessor and mutator as follows: Remove the addFuel method from class Car Replace the call to addFuel in the main program with a call to the accessor and mutator for the fuel amount to achieve the same effect (add 5 gallons of fuel to the existing fuel in the Toyota Camry). Test your program again to make sure it works and produces the same output. Part 2: Add functions to remove duplicate code * In the main program,...
Using C# Create an application class named LetterDemo that instantiates objects of two classes named Letter and CertifiedLetter and that demonstrates all their methods. The classes are used by a company to keep track of letters they mail to clients. The Letter class includes auto-implemented properties for the Name of the recipient and the Date mailed (stored as strings). Next, include a ToString() method that overrides the Object class’s ToString() method and returns a string that contains the name of...
// Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...
Create a class named Poem that contains the following fields: title - the name of the poem (of type String) lines - the number of lines in the poem (of type int) Include a constructor that requires values for both fields. Also include get methods to retrieve field values. Create three subclasses: Couplet, Limerick, and Haiku. The constructor for each subclass requires only a title; the lines field is set using a constant value. A couplet has two lines, a...