Monday, July 16, 2007

Review Exercises

Problem #1: Data Types and Variables
Create a console application that accepts 4 int values from the user, and compute and output the following
  • The sum of the 4 integers
  • The product of the 4 integers
  • The difference between integers 1 and 2
  • The quotient between integers 3 and 4 expressed as a float type
Hint: Recall the Convert.Totype-name() or type-name.Parse() methods for converting a string to a numeric type. Also recall how to cast one data type to another to get the desired value.

Sample program output:

Enter integer 1: 10
Enter integer 2: 5
Enter integer 3: 8
Enter integer 4: 14

Sum: 37
Product: 5600
Difference (1 and 2): 5
Quotient (3 and 4): 0.5714286

Problem #2: Control Structures (Conditionals, Loops)
Create a console application that accepts a number of student grades to process. The application should loop through this number to get the grade for each student.

For each grade input, the application should check if the grade is within 60 to 100. If the grade is invalid, the application should display an error and ask for input again.

If the grade is valid, the application should check if the student passed or failed (failing grade is between 60 to 74) and should increment the appropriate count for passed or failed students (declared as variables). The application should also be able to compute the percentage of passed and failed students.

Sample program output:

Enter number of students to process: 10

Enter grade for student 1 (60-100): 80
Enter grade for student 2 (60-100): 10
Error: Grade must be within 60 to 100
Enter grade for student 2 (60-100): 74
...
Enter grade for student 10 (60-100): 90

Total no. of students: 10
No. of students who passed: 6
No. of students who failed: 4

Percentage of students who passed: 60%
Percentage of students who failed: 40%


Problem #3: Classes - Constructors, Fields, Properties and Methods
Create a class called MathUtil which implements the basic arithmetic functions defined in Problem #1. The choice on how to define the constructors, fields, properties or methods is totally up to you.