Question

In: Computer Science

#C. Write a program that accepts any number of homework scores ranging in value from 0...

#C.

Write a program that accepts any number of homework scores ranging in value from 0 through 10. Prompt the user for a new score if they enter a value outside of the specified range. Prompt the user for a new value if they enter an alphabetic character. Store the values in an array. Calculate the average excluding the lowest and highest scores. Display the average as well as the highest and lowest scores that were discarded.

Solutions

Expert Solution

Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HomeWorkDemo
{
class Program
{
static void Main(string[] args)
{
string score;
int score1;
int nums;
Console.Write("How many Homework scores do you want to enter? : ");
nums = Convert.ToInt32(Console.ReadLine());

int[] scores = new int[nums];
for(int i=0;i< nums;i++)
{
Console.Write("Enter Score"+(i+1)+": ");
score = Console.ReadLine() ;
int p;

if (int.TryParse(score, out p))
{
score1 = Convert.ToInt32(score);
if (score1 >= 0 && score1 <= 10)
{
scores[i] = score1;
}

else
{
while (true)
{
Console.Write("Please Enter valid Score" + (i + 1) + ": ");
score1 = Convert.ToInt32(Console.ReadLine());
if (score1 >= 0 && score1 <= 10)
{
scores[i] = score1;
break;
}
}
}
}
else
{
while (true)
{
Console.Write("Please Enter valid Score" + (i + 1) + ": ");
score1 = Convert.ToInt32(Console.ReadLine());
if (score1 >= 0 && score1 <= 10)
{
scores[i] = score1;
break;
}
}
}

  

}

Console.WriteLine("\nStored Values of the Array: ");
for (int i = 0; i < scores.Length; i++)
{
Console.Write(scores[i] + " ");
}
int max = scores[0];
int min = scores[0];

for (int i = 0; i < scores.Length ; i++)
{
if (max < scores[i])
{
max = scores[i]; //storing maximum value in max
}

if (min > scores[i])
{
min = scores[i]; //storing minimum value in min
}
}

int sum = 0;
double avg;
int c = 0;
for (int i = 0; i < scores.Length; i++)
{
if (!(scores[i] == min || scores[i] == max))
{
sum = sum + scores[i]; //sum of stored values except highest and lowest
c++;
}
}
avg = (double)sum / c;
Console.WriteLine("\n\nThe Average: "+Math.Round(avg,2));
Console.WriteLine("Highest Score: "+max);
Console.WriteLine("Lowest Score: "+min);
Console.ReadKey();
}
}
}

output:


Related Solutions

Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
Write a C++ program that accepts a single integer value entered by user. If the value...
Write a C++ program that accepts a single integer value entered by user. If the value entered is less than one the program prints nothing. If the user enters a positive integer n. The program prints n x n box drawn with * characters. If the user enters 1 , for example the program prints *. If the user enter a 2, it prints ** ** that is , a 2x2 box of * symbols.
Write a program in C A teacher will assign homework and give the number of days...
Write a program in C A teacher will assign homework and give the number of days for the students to work on. The student is responsible for calculating the due date. The teacher does not collect homework on Friday or weekend. Write a C program that let the user enter today’s day of the week (0 for Sunday, 1 for Monday, etc.) and the number of days to allow the students to do the work, which may be several weeks....
Using Visual Studio write a program that allows the user to enter multiple scores ranging from...
Using Visual Studio write a program that allows the user to enter multiple scores ranging from 0 to 100, computes the average of those scores and then writes out a letter grade using the typical grading scale. Your program will also: 1. Allow the user to enter any number of scores he or she wishes but assume there will be at least one score entered. 2. Use a sentinel-controlled loop variable to terminate the loop when the user has no...
Write a C program that accepts a port number as a command line argument, and starts...
Write a C program that accepts a port number as a command line argument, and starts an HTTP server. This server should constantly accept() connections, read requests of the form: GET /path HTTP/1.1\r\n\r\n read the file indicated by /path, and send it over the "connect" file descriptor returned by the call to accept().
Write a C program that accepts a port number as a command line argument, and starts...
Write a C program that accepts a port number as a command line argument, and starts an HTTP server. This server should constantly accept() connections, read requests of the form GET /path HTTP/1.1\r\n\r\n read the file indicated by /path, and send it over the "connect" file descriptor returned by the call to accept().
Write a computer program using C++ that computes the value of a Lagrange Polynomial and accepts,...
Write a computer program using C++ that computes the value of a Lagrange Polynomial and accepts, as input: (n+1) data points (x0, f(x0)), (x1, f(x1)),...(xn, f(xn)).. at value x, which the polynomial is to evaluated. As output, the program should produce a statement that reads, "f(x) = (the value of f(x))". As a test, use the data values (1,2);(-1,1);(0,0);(2,4);(-2,3)
Write a C++ program to input 10 scores (range from 0-100), calculate the average, then display...
Write a C++ program to input 10 scores (range from 0-100), calculate the average, then display the student's name, and a letter grade such as A, B, C, D, or F. It shall have a Student class with necessary private data members and constructor and public methods, such as getName, getGrade, calcScore, convertToGrade, etc. Try to create a Student object in main(), then invoke its methods to perform the tasks.
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
3. Write a program using switch-case statements that accepts an integer number between 0 and 100...
3. Write a program using switch-case statements that accepts an integer number between 0 and 100 and, based on its value, reports its equivalent letter grade (A, B, C, D, or F).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT