Question

In: Computer Science

Please code in C# - (C - Sharp) Assignment Description Write out a program that will...

Please code in C# - (C - Sharp)

Assignment Description

Write out a program that will ask the user for their name; the length and width of a rectangle; and the length of a square. The program will then output the input name; the area and perimeter of a rectangle with the dimensions they input; and the area and perimeter of a square with the length they input.

Tasks

  1. The program needs to contain the following
    1. A comment header containing your name and a brief description of the program
    2. Output prompting the user for the following inputs:
      1. Name as a string
      2. Length of a rectangle as a double
      3. Width of a rectangle as a double
      4. Length of a square as an int
    3. After accepting user input, the program outputs the following:
      1. User name
      2. Area of a rectangle with dimensions matching the inputs
        • Area of a rectangle = Length * Width
      3. Perimeter of a rectangle with dimensions matching the inputs
        • Perimeter of a rectangle = (2 * length) + (2 * Width)
      4. Area of a square with dimensions matching the inputs
        • Area of a square = Length * Length
      5. Perimeter of a square with dimensions matching the inputs
        • Area of a square = 4 * length
    4. “Press enter to continue”
    5. Console.Read(); at the end of your code

Solutions

Expert Solution

Code Screenshots:

Sample Output:

Code To Copy:

//Use the

//required modules.

using System;

//Define

//the MainClass.

class MainClass

{

    //Define the

    //Main() method.

    public static void Main(string[] args)

    {

        //Declare the

        //required variables.

        string name;

        double rect_length;

        double rect_width;

        int square_length;

        double area_rect;

        int area_square;

        double perimeter_rect;

        int perimeter_square;

        //Prompt the user

        //to enter the name.

        Console.Write("Enter the name: ");

        //Read and store the name.

        name = Console.ReadLine();

        //Prompt the user to enter

        //the length of the rectangle.

        Console.Write("Enter the length of the rectangle: ");

        //Read and store the

        //length of the rectangle.

        rect_length = Double.Parse(Console.ReadLine());

        //Prompt the user to enter

        //the width of the rectangle.

        Console.Write("Enter the width of the rectangle: ");

        //Read and store the

        //width of the rectangle.

        rect_width = Double.Parse(Console.ReadLine());

        //Prompt the user to enter

        //the length of the square.

        Console.Write("Enter the length of the square: ");

        //Read and store the

        //length of the square.

        square_length = Convert.ToInt32(Console.ReadLine());

        //Calculate the area

        //of the rectangle.

        area_rect = rect_length * rect_width;

        //Calculate the

        //perimeter of the rectangle.

        perimeter_rect = (2 * rect_length) + (2 * rect_width);

        //Calculate the

        //area of the square.

        area_square = square_length * square_length;

        //Calculate the

        //perimeter of the square.

        perimeter_square = 4 * square_length;

        //Display the name.

        Console.WriteLine("Name: {0}", name);

       

        //Display the required results.

        Console.WriteLine("Area of rectangle: {0}", area_rect);

        Console.WriteLine("Perimeter of rectangle: {0}", perimeter_rect);

        Console.WriteLine("Area of square: {0}", area_square);

        Console.WriteLine("Perimeter of square: {0}", perimeter_square);

        Console.WriteLine("Press enter to continue");

        Console.Read();

    }

}


Related Solutions

Please code in c# (C-Sharp) Write a program that will ask the user for their name....
Please code in c# (C-Sharp) Write a program that will ask the user for their name. If the user does not input anything, display a warning before continuing. The program will then ask the user whether they want to have an addition, subtraction, multiplication, or division problem. Once the user indicates their choice, the program will display 2 randomly generated numbers from 1 to 9 in a math problem matching the user’s choice. Example: user selects addition, the equation presented...
Please code in C# (C-Sharp) Assignment Description A pirate needs to do some accounting and has...
Please code in C# (C-Sharp) Assignment Description A pirate needs to do some accounting and has asked for your help. Write a program that will accept a pirate’s starting amount of treasure in number of gold pieces. The program will then run one of two simulations, indicated by the user: 1) The first simulation runs indefinitely, until one of two conditions is met: the pirate’s treasure falls to 0 or below, or the pirate’s treasure grows to 1000 or above....
How to write this mini program in C# - (C sharp please) There are 3 squirrels...
How to write this mini program in C# - (C sharp please) There are 3 squirrels and winter begins in roughly 12 weeks Each week, a squirrel will manage to stash away anywhere from 10 to 20 acorns Each week, display the following: ◦ The number of weeks before winter ◦ The number of acorns each squirrel stashed away that week ◦ The total number of acorns each squirrel has stashed away Bonus: display the number of acorns stashed each...
Assignment Description: Write a C++ program for keeping a course list for each student in a...
Assignment Description: Write a C++ program for keeping a course list for each student in a college. Information about each student should be kept in an object that contains the student id (four digit integer), name (string), and a list of courses completed by the student. The course taken by a student are stored as a linked list in which each node contain course name (string such as CS41, MATH10), course unit (1 to 4) and the course grade (A,B,C,D,F)....
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure...
PLEASE CODE IN JAVA In this assignment you will write a program in that can figure out a number chosen by a human user. The human user will think of a number between 1 and 100. The program will make guesses and the user will tell the program to guess higher or lower.                                                                   Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your...
*Please write code in C++* Write a program to verify the validity of the user entered...
*Please write code in C++* Write a program to verify the validity of the user entered email address.   if email is valid : output the stating that given email is valid. ex: "The email [email protected] is valid" else : output the statement that the email is invalid and list all the violations ex:  "The email sarahwinchester.com is invalid" * @ symbol * Missing Domain name The program should keep validating emails until user enter 'q' Upload your source code. ex: main.cpp
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program...
Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3. Your program will contain three functions: Function #1: Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into BMI is as follows: BMI = Weight *...
Description: The purpose of this assignment is to write code that calculates the amount of interest...
Description: The purpose of this assignment is to write code that calculates the amount of interest accrued on a credit card on its expenses. You will create a C program that prompts the user for the total amount of purchases on the credit card, an annual percentage rate (APR), and the number of days the money is borrowed. The program will calculate the amount of the compound interest for the purchases, then print the original amount of purchases, the amount...
Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT