Question

USING VISUAL BASIC STUDIO PLEASE PROVIDE THE CODE IN C# LANGUAGE SELECT CONSOLE APPLICATION You are...

USING VISUAL BASIC STUDIO PLEASE PROVIDE THE CODE IN C# LANGUAGE SELECT CONSOLE APPLICATION

You are to create a House with 2 rooms in the house. The following is an example of C++ code for the basic classes: **in C#, it may be written differently**

class Room

{

private:

double L;

double W;

public:

//functions go here.

}

class House

{

private:

Room room1;

Room room2;

public:

//functions go here

}

The code above is C++ version. In C#, you must make the variables private. Dont forget to use the "new" command. Basic Example: House h = new House();

*Make sure each class is in its own file with the correct functions and data types*

The program will basically ask the user to input a L and W for a room, then ask for L and W for the other room. It will then calculate which of the two rooms is bigger. It should assign the bigger room to the parents and smaller room to children. State: "parents get room #_ of size __", "children get room #_ of size __".

Make sure to actually use the class objects for this program. Not using the object will result in a zero. (this means the class object has functions which have access to the private variables of the class, use them).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;

public class Room

{

private double L;

private double W;

public Room(double L,double W) //constructor

{

this.L = L;

this.W = W;

}

//get methods

public double getL()

{

return L;

}

public double getW()

{

return W;

}

//area method

public double area()

{

return L*W;

}

}

public class House

{

private Room room1;

private Room room2;

public House(Room room1,Room room2) //constructor with objects as arguments

{

this.room1 = room1;

this.room2 = room2;

}

//compare two rooms using their areas

public bool biggerRoom()

{

if( room1.area() > room2.area())

return true; //return true if room1 is bigger than room2

else

return false;

}

}

public class Test

{

public static void Main()

{

double l,w;

Console.WriteLine("Enter the Length and Width of Room 1 : ");

l = Convert.ToDouble(Console.ReadLine());

w = Convert.ToDouble(Console.ReadLine());

Room r1 = new Room(l,w);

Console.WriteLine("\nEnter the Length and Width of Room 2 : ");

l = Convert.ToDouble(Console.ReadLine());

w = Convert.ToDouble(Console.ReadLine());

Room r2 = new Room(l,w);

House h = new House(r1,r2);

if(h.biggerRoom())

Console.WriteLine("\nparents get room #1 of size "+ r1.area()+ " children get room #2 of size "+r2.area()+".");

else

Console.WriteLine("\nparents get room #2 of size "+ r2.area()+ " children get room #1 of size "+r1.area()+".");

}

}

Output:

Enter the Length and Width of Room 1 : 
23.4
44.3

Enter the Length and Width of Room 2 : 
32.1
46.7

parents get room #2 of size 1499.07 children get room #1 of size 1036.62.
Add a comment
Know the answer?
Add Answer to:
USING VISUAL BASIC STUDIO PLEASE PROVIDE THE CODE IN C# LANGUAGE SELECT CONSOLE APPLICATION You are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets...

    This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets and sets methods for the variables. Create a No-Arg constructor and a constructor that accepts all three values. At the end of the class add a main method that accepts variables from the user as input to represent the length and width of a room in feet and the price of carpeting per square foot in dollars...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to...

  • Language is C++ Basic principles and theory of structured programming in C++ by implementing the class:...

    Language is C++ Basic principles and theory of structured programming in C++ by implementing the class: Matrix Use these principles and theory to help build and manipulate instances of the class (objects), call member functions Matrix class implementation from the main function file and, in addition, the Matrix class must have its interface(Matrix.h) in a separate file from its implementation (Matrix.cpp). The code in the following files: matrix.h matrix.cpp matrixDriver.h Please use these file names exactly. Summary Create three files...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Program 2: Design (pseudocode) and implement (source code) a class called Counter. It should have one private instance variable representing the value of the counter. It should have two instance methods: increment() which adds on to the counter value and getValue() which returns the current value. After creating the Counter class, create a program that simulates tossing a coin 100 times using two Counter objects (Head...

  • Recursion program C++. Visual Studio Win 32 console application that has user loop. The Design a...

    Recursion program C++. Visual Studio Win 32 console application that has user loop. The Design a computer program a executes the program, should do the following. computer, as it 1) The computer should politely ask the user for two input integers m and n. There should be code to make sure that m <-n 2) Then there should be a recursive function, called LargestToSmallestO that is invoked to output all the values from n downto m. 3) Then there should...

  • Using C# Language Develop a Visual C# .NET application that performs a colour control operation. The...

    Using C# Language Develop a Visual C# .NET application that performs a colour control operation. The main form contains a reset button and sets the form's background colour according to the colour values indicated by the colour control objects. Each colour control object is controlled by a corresponding colour control form which provides a progress bar to show the value (in the range 0 to 255) of the corresponding colour control object. The user can click the increase (+) or...

  • C# assistance please help Write the source code for a C# program (i.e., a separate class)...

    C# assistance please help Write the source code for a C# program (i.e., a separate class) named “BookDemo” that uses the Book class below and does the following in the Main method of BookDemo: 1) Declare local variables for book title and author, and initialize the variables to “C# Programming” and “Farrell” 2) Instantiate a Book object using the information from Step 1 3) Print the summary of the book object using the displaySummary() method in the Book class class...

  • Please answer this question clearly and correctly! the code should be handwritten if all possible!! ALSO MAKE SURE IT IS WRITTEN IN C++! thank you so much in advance and I will upvote when done right...

    Please answer this question clearly and correctly! the code should be handwritten if all possible!! ALSO MAKE SURE IT IS WRITTEN IN C++! thank you so much in advance and I will upvote when done right! (26 points total) Write an inheritance hierarchy for classes of simple shapes. 1. Create a class Shape. Derive the class ThreeDimensionalShape from the Shape class. Derive the class Sphere from the ThreeDimensionalShape class Use abstract classes to define Shape and ThreeDimensionalShape classes, and then...

  • The language is C++ for visual studio express 2013 for windows create a TicketManager class and...

    The language is C++ for visual studio express 2013 for windows create a TicketManager class and a program that uses the class to sell tickets for a performance at a theater. Here are all the specs. This is an intense program, please follow all instructions carefully. -I am only creating the client program that uses the class and all it's functions -The client program is a menu-driven program that provides the user with box office options for a theater and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT