Question

In: Computer Science

OBJECTIVE Upon completion of this exercise, you will have demonstrated the ability to: Use C# loops...

OBJECTIVE

Upon completion of this exercise, you will have demonstrated the ability to:

  • Use C# loops
  • Construct conditions

INTRODUCTION

Your instructor will assign one of the following projects, each involves the user of loops and the construction of conditions to control them.

CODING STANDARDS

The following coding standards must be followed when developing your program:

  • An opening documentation at the beginning of the source file describing the purpose, input, process, output, author, last modified date of the program.
  • Write only one statement per line.
  • Write only one declaration per line.
  • Use camelCase for local variable names.
  • Use UPPER_CASE for constant variable names.
  • If continuation lines are not indented automatically, indent them one tab stop (four spaces).
  • Do NOT use goto or break statements in your looping structure.

PROJECTS

  1. Create a C# Console App named CPSC1012-Exercise04-YourName where YourName is your first and last name.
  2. Solve the problems below:
    1. Write a program that will read a sequence of numbers from the keyboard (you are free to choose the input flow method of your choice), and display the minimum, maximum, average, and range (highest minus lowest) of the entered values.  Validate the input.

DEMONSTRATION/SUBMISSION REQUIREMENTS

  1. Demonstrate the execution of your program in which you show all functionality of your program.
  2. Upload your completed project to Moodle.

Solutions

Expert Solution

Code:

using System;

class Test

{

static void Main()

{

//First we take user input for number of inputs and assign to n after Integer Conversion

Console.Write("Enter Number Of Inputs: ");

int n = Convert.ToInt32(Console.ReadLine());

//We create an integer array of size n

int[] num = new int[n];

//We use for loop to take n numbers as input and assign to array

for(int i = 0; i < n ; i++)

{

Console.Write("Enter Number "+(i+1)+": ");

num[i] = Convert.ToInt32(Console.ReadLine());

}

//Initialising Variables

int sum = 0, min = num[0], max = num[0];

//We again use for loop to go through values to fond sum, min and max

for(int i = 0; i < n ; i++)

{

if(num[i] < min)

{min = num[i];}

if(num[i] > max)

{max = num[i];}

sum = sum + num[i];

}

//Calculating Range and Average

double avg = (1.0 * sum)/n;

int range = max - min;

//Printing results

Console.WriteLine("Minimum: "+min);

Console.WriteLine("Maximum: "+max);

Console.WriteLine("Average: "+avg);

Console.WriteLine("Range: "+range);

}

}


Related Solutions

Upon completion of this exercise, you will have demonstrated the ability to: Use C# loops Construct...
Upon completion of this exercise, you will have demonstrated the ability to: Use C# loops Construct conditions INTRODUCTION Your instructor will assign one of the following projects, each involves the user of loops and the construction of conditions to control them. CODING STANDARDS The following coding standards must be followed when developing your program: An opening documentation at the beginning of the source file describing the purpose, input, process, output, author, last modified date of the program. Write only one...
Objective: Upon completion of this program, you should gain experience with overloading basic operators for use...
Objective: Upon completion of this program, you should gain experience with overloading basic operators for use with a C++ class. The code for this assignment should be portable -- make sure you test with g++ on linprog.cs.fsu.edu before you submit. Task Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). The class, along with the required operator overloads, should be written in the...
use formulas to solve the problems 7. Your financial objective is to have $3,000,000 upon your...
use formulas to solve the problems 7. Your financial objective is to have $3,000,000 upon your retirement 40 years from now. If you have committed to make an equal annual deposit into an investment account that provides 9 percent annual return, how much will the annual deposit be? 8. If you invest $30,000 a year, every year in an account that earns 8 percent annual return, how long will it take for the balance in the account to reach $2,000,000?
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output....
Objective: Write this program in the C programming language Loops with input, strings, arrays, and output. Assignment: It’s an organization that accepts used books and then sells them a couple of times a year at book sale events. Some way was needed to keep track of the inventory. You’ll want two parallel arrays: one to keep track of book titles, and one to keep track of the prices. Assume there will be no more than 10 books. Assume no more...
This exercise will test your ability to use the basic instance methods of String. The exercise...
This exercise will test your ability to use the basic instance methods of String. The exercise is to create a program that compares two Strings ignoring the case and returns the offset between the first two distinct characters in the two Strings from left to right. All the input strings have five characters. For this exercise, compareToIgnoreCase() and compareTo() methods are not allowed. Example 1, "London" and "Lately" will return the offset between 'o' and 'a', which is 14 Example...
Question Objective: The objective of this lab exercise is to give you practice in programming with...
Question Objective: The objective of this lab exercise is to give you practice in programming with one of Python’s most widely used “container” data types -- the List (commonly called an “Array” in most other programming languages). More specifically you will demonstrate how to: Declare list objects Access a list for storing (i.e., writing) into a cell (a.k.a., element or component) and retrieving (i.e., reading) a value from a list cell/element/component Iterate through a list looking for specific values using...
Upon successful completion of the MBA program, imagine you work in the analytics department for a...
Upon successful completion of the MBA program, imagine you work in the analytics department for a consulting company. Your assignment is to analyze the following databases: Hospital Provide a detailed, four part, statistical report with the following sections: Part 1 - Preliminary Analysis Part 2 - Examination of Descriptive Statistics Part 3 - Examination of Inferential Statistics Part 4 - Conclusion/Recommendations Part 1 - Preliminary Analysis Generally, as a statistics consultant, you will be given a problem and data. At...
DOES THE GOOD LIFE DEPEND UPON OBJECTIVE VALUE? You have read different and in some ways,...
DOES THE GOOD LIFE DEPEND UPON OBJECTIVE VALUE? You have read different and in some ways, opposing, viewpoints on what is necessary to live a good life.   The assignment: Provide two or more paragraphs in response to this question: does the ood liffe depend upon objective values? Provide at least three supporting facts in agreement or, if you disagree, provide at least three supporting facts in disagreement."
What are pre-test loops. Which C++ statements use pre-test loops? Why pre-test loops are called 0...
What are pre-test loops. Which C++ statements use pre-test loops? Why pre-test loops are called 0 to N loops? When do you use the pre-test loops? Give at least one example.
Upon completion of your nursing degree, you decided to try the country life, and moved to...
Upon completion of your nursing degree, you decided to try the country life, and moved to a rural town in West Virginia, working for a small family practice. Around mid-September, a man in his late 40’s comes in to your office. He has been suffering from an intermittent headache with a fever of 102-103°F for the past two weeks. The physician arrives while you are completing his vitals (nothing abnormal was noted). The physician takes the man’s history, and performs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT