This is my current try catch statement. I dont know why it exists when empty file read in:
// convert each string into an integer and store in "eachInt[]"
string fileContents = System.IO.File.ReadAllText(fileName);
string[] eachString = fileContents.Split(new char[] { '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
int[] eachInt = new int[eachString.Length];
try
{
for (int i = 0; i < eachString.Length; i++)
{
if (IsNumeric(eachString[i]))
{
eachInt[i] = int.Parse(eachString[i]);
}
// else
//{
// continue;
//}
}
eachInt = eachInt.Where(val => val != 0).ToArray();
}
catch(IndexOutOfRangeException)
{
MessageBox.Show("File contained no integers, try a different file.");
return;
}
2. Name the class as SalaryCalculator and save the file
3. Compile and execute the program using command prompt
4. Correct syntax and logical errors if there is any
3. Name the class as AverageGradeCalculator and save the file.
4. Compile and execute the program using command prompt
5. correct and syntax and logical errors if there is any.
Write a c++ program to plot a graph of function f(x) = x
n + xn-1
. Your program should take a maximum
absolute value of x as well as a positive integer n as input. You will plot a graph for the range [0, x]. You
should label the y-axis according to the maximum value of x.
Sample Output: For x = 3 and n = 2, you should have the following output
12 *
10
08
06 *
04
02 *
00 *
0 1 2 3
Write a program that calculates the occupancy rate for a hotel. The program should start by asking the
user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration,
the loop should ask the user for the number of rooms on the floor and how many of them are occupied.
After all the iterations, the program should display how many rooms the hotel has, how many of them
are occupied, how many are unoccupied, and the percentage of rooms that are occupied. The
percentage may be calculated by dividing the number of rooms occupied by the number of rooms.
Input Validation: Do not accept a value less than 1 for the number of floors. Do not accept a number
less than 10 for the number of rooms on a floor.
Take n as input from the user. Calculate the sum of the following series up to n-th term using a recursive function.2*3*4 + 4*5*3 + 8*7*2 + 16*9*1 + ⋯
Sample input
3
Sample output:
24+60+112=196
Sample input:
6
Sample output :
24+60+112+144+0+(-832)=-492
Take two positive integers a and b as input from user. Write a recursive program to print all the even numbers in range [a, b].
Sample input:
1 8
Sample output:
1 8 2 4 6 8
Sample input :
2 11
Sample output::
2 4 6 8 10
Exceptions:
1. Create a situation where an exception will occur
2. Create a situation where an exception will occur, and catch the exception.
3. Create a situation where an exception will occur, and catch the exception, the display a custom message.
4. Create a situation where an exception will occur, and catch the exception, then display the caught exception’s internal message.
5. Write code utilize the finally block
6. Create a situation where an exception will occur, and pass the exception to be handled up the chain.
7. Create a situation where no exception will occur, but generate an exception anyway.
by CodeChum Admin
Instructions:
Input
The first line contains the size of the array/list.
The next lines contains an integer on each.
5
5
34
3
23
10Output
A line containing an integer.
34by CodeChum Admin
We've already tried printing out the values of an array in reversed order, right? Today, we shall compute for the squares of all the numbers.
There's already a predefined array/list containing 100 integer values. Loop through each values, compute their squares, and display them.
Output
Multiple lines containing an integer.
4
9
25
10000
49
9
25
9
1
16
.
.
.