Question

Challenge: C# Basics Description: Write a C# console application using .NET Core that utilizes constants, variables,...

Challenge: C# Basics

Description: Write a C# console application using .NET Core that utilizes constants, variables, data types, operators, expressions, statements, blocks, and control flow.

Purpose: This application provides experience in working with basic language features of C#. It is important when working with a new language to understand how it handles its constants, variables, data types, operators, expressions, statements, blocks, and control flow. A good thing to always do with a new language is to build test applications where you experiment with these language features to make sure you understand how they work.

Requirements:

Project Name: Csharp Basics
Target Platform: Console Application
Programming Language: C#

Write the code necessary to do the following inside the Main function of the C# program.

Declare the following constants and variables and set their initial values as indicated.

  • Declare a constant of type byte named sample1 with an initial value of 0x3A

  • Declare a variable of type byte named sample2 with an initial value of 58

  • Declare a variable of type int named heartRate with an initial value of 85

  • Declare a variable of type double named deposits that has an initial value of 135002796

  • Declare a constant float named acceleration that has an initial value of 9.800

  • Declare a variable float named mass that has an initial value of 14.6

  • Declare a variable double named distance that has an initial value of 129.763001

  • Declare a variable bool named lost that has an initial value of true

  • Declare a variable bool named expensive that has an initial value of true

  • Declare a variable int named choice with an initial value of 2

  • Declare a constant of type char named integral that has a value of \u222B

  • Create a constant String named greeting that has an initial value of “Hello”

  • Create a variable String named name that has an initial value of “Karen”

Using the constants and variables declared and initialized based on the above, do the following. Where is says “display” it means output a line to standard out. Each displayed item is to be on a separate line.

Compare sample1 to sample2 and if they are equal display “The samples are equal.” otherwise display “The samples are not equal.”

If heartRate is greater than equal to 40 and less than equal to 80 display “Heart rate is normal.” otherwise display “Heart rate is not normal.”

If deposits is greater than or equal to 100000000 display “You are exceedingly wealthy.” otherwise display “Sorry you are so poor.”

Declare a variable called force that is assigned to the mass times the acceleration. The force variable must be of the same type as the type that results from the multiplication of mass and acceleration.

Display the calculated force preceded by the string “force = ”. The output should look like the following (actual value will be different): force = 2.345

Display the value of distance followed by “ is the distance.”

Using lost and expensive display “I am really sorry! I will get the manager.” if lost and expensive are both true and “Here is coupon for 10% off.” if lost is true and expensive is false.

Use switch/case and the variable choice to display “You chose 1.” if choice is 1, “You chose 2.” if choice is 2, “You chose 3.” if choice is 3, and “You made an unknown choice.” if choice is something other than 1, 2, or 3.

Using the char constant integral, display the character in integral followed by the string “ is an integral.”

Using a “for” loop count from 5 to 10 (inclusive of start and end) using an int variable i. Inside the loop display each value of i with a line that is “i = ” followed by the value of i as in:

i = 5
i = 6
i = 7
i = 8
i = 9
i = 10

Declare an int variable age with an initial value of 0. Using a “while” loop that continues while age is less than 6 display the value of age in a line that begins with “age = ” and is followed by the value of age. (Example: age = 3) After the age line is displayed increment the value of age by 1.

Display a line that contains the greeting String followed by a space followed by the name String.

PLEASE COPY DOWN WITH ALL INDENTATIONS AND SPACING :)

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

Dear Student ,

As per requirement submitted above kindly find below solution.

Here new console application in C# in .net core is created using visual studio 2019 with name "CsharpBasics". This application contains a class with name "Program.cs".Below is the details of this class.

Program.cs :

//namespace
using System;
//application namespace
namespace CsharpBasics
{
class Program //C# class
{
//Main() method , entry point of the application
static void Main(string[] args)
{
//declaring constant of type byte
const byte sample1 = 0x3A;
//declaring constant of type byte
const byte sample2 = 58;
//declaring variable of type int
int heartRate = 85;
//declaring a variable of type double
double deposits = 135002796;
//declaring a constant float
float acceleration = 9.800F;
//declaring a variable float
float mass = 14.6F;
//declaring a variable double
double distance = 129.763001;
//declaring a variable bool
bool lost = true;
//declaring a variable bool
bool expensive = true;
//declaring a variable int
int choice = 2;
//declaring constant of type char
char integral ='\u222B';
//declaring constant String
const string greeting = "Hello";
//declaring a variable String
string name = "Karen";
//Comparing sample1 to sample2
if(sample1==sample2)
{
//comparing two samples
Console.WriteLine("The samples are equal.");
}
else
{
Console.WriteLine("The samples are not equal.");
}
//checking heartRate
if(heartRate>=40 && heartRate<=80)
{
//if hearRate is greater than or equal to 40 and
//less than or equal to 80 then
Console.WriteLine("Heart rate is normal.");
}
else
{
Console.WriteLine("Heart rate is not normal.");
}
//checking deposit
if (deposits >= 100000000)
{
//if deposit is greater than or equal to
Console.WriteLine("You are exceedingly wealthy.");
}
else
{
Console.WriteLine("Sorry you are so poor");
}
//declaring a variable
float force = mass * acceleration;
//display force
Console.WriteLine("force = "+force);
//displaying value of distance
Console.WriteLine(distance+ " is the distance");
//checking lost and expensive
if(lost==true && expensive==true)
{
//if both lost and expensive are true then
Console.WriteLine("I am really sorry! I will get the manager.");
}
else if(lost==true && expensive==false)
{
//if lost is true and expensive is false then
Console.WriteLine("Here is coupon for 10% off.");
}
//using switch case
switch (choice)
{
case 1: Console.WriteLine("You chose 1.");
break;
case 2: Console.WriteLine("You chose 2.");
break;
case 3: Console.WriteLine("You chose 3.");
break;

default:
Console.WriteLine("You made an unknown choice.");
break;
}
//display char constant
Console.WriteLine(integral+ " is an integral.");
//using for loop
for (int i= 5;i<=10; i++)
{
//display value of i
Console.WriteLine("i="+i);
}
//declaring int variable
int age = 0;
//using while loop
while (age<6)
{
//display value of age
Console.WriteLine("age="+age);
age = age + 1;//increment value of age
}
//display greeting
Console.WriteLine(greeting+" "+name);
}
}
}
==================================

Output :Run application using F5 and will get the screen as shown below

Screen 1:Program.cs

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Challenge: C# Basics Description: Write a C# console application using .NET Core that utilizes constants, variables,...
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
  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • Using Swift playground and / or the command line for macOS (open Xcode, create a new...

    Using Swift playground and / or the command line for macOS (open Xcode, create a new Xcode project, macOS, command line tool), practice the following exercises: Exercise: Swift Variables Declare 2 variables/constants with some random values and any name of your choice Considering these 2 variables, one as a value of PI and other as a radius of circle, find the area of circle Print the area of circle Declare a string variable explicitly with value “Northeastern”. Declare a string...

  • This has to be extremely precise, thank you for your time. ols Window Help U +...

    This has to be extremely precise, thank you for your time. ols Window Help U + 1 /write a class meeting the following specifications: 3 //The class is declared as public. 4 //The class is named Country. 5 //The class has a field of type String named anger. 6 //The class has a field of type int named stretch. 7 //The class has a field of type double named film. 8 //The class has a exactly one constructor. 9 //The...

  • This needs to be done in c++11 and be compatible with g++ compiling Project description: Write...

    This needs to be done in c++11 and be compatible with g++ compiling Project description: Write a C++ program to simulate a simple card game between two players. The game proceeds as follows: The 52 cards in a deck of cards are shuffled and each player draws three cards from the top of the deck. Remaining cards are placed in a pile face-down between the two players. Players then select a card from the three in their hand. The player...

  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...

  • You've been hired by Rugged Robots to complete a C++ console application that controls a robotic...

    You've been hired by Rugged Robots to complete a C++ console application that controls a robotic floor vacuum. Wayne State software engineers have already developed the following three files: File Description Lab20-01-Key.cpp This is the user application. RuggedRobotLibrary.h This is the library header file. It contains constant declarations and function prototypes. It is included by the other two files. RuggedRobotLibrary.cpp This is the library file. It contains functions that may be used in any user application. This is considered an...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

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

  • Use BlueJ to write a program that reads a sequence of data for several car objects...

    Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info for any number of cars. (You should not assume that it will always be seven lines in the input file). Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

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