Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3871407 • Letter: U

Question

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).

Explanation / Answer

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(" Enter 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(" parents get room #1 of size "+ r1.area()+ " children get room #2 of size "+r2.area()+".");

else

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

}

}

Output: