You are on page 1of 8

Narrative

This guide is the formal road map for this course. It contains all lecture topics, reading assignments, in-class labs, test dates and homework labs. This is basically the map well use to navigate through the C# world.

C# Homework Problems
There are 39 C# programs to be written throughout the semester. Some are fairly easy and some are fairly difficult. All of these programming problems have been completed by students in previous semesters. These programs are a combination of engineering, computer science and business-based problems. The programs are due the week after we complete the respective chapter. Each chapters problems should be turned in together, stapled with a cover page and the following information. All programs, labs and homework, should have your name, class, problem number and date in comment form in the programs header similar to below.
// // // // // // // // --------------------------------------------------------------Program Name: prob15.cs Problem Number: Problem 15 Author: Your Name Class: CIS162AD Date: August 19, 2008 Description: This program does the following: some text ---------------------------------------------------------------

Chapter 2 Problems 1.) Display Student Information. Write a C# program to display your name, address, phone number and email address, hobbies and interests, and your college major. Use a Console.WriteLine function for each piece of information. Include lots of C# comments. 2.) Display Your Birth Year. Write a simple C# program to display your birth year both horizontally and vertically. Include lots of C# comments. Output should look similar to: My Birth Year is 1972 My Birth Year is 1 9 7 2

Chapter 3 Problems 3.) Prompting For Numbers. This program has two sections. The first part will prompt for 5 integer numbers. Find the sum and average of these five numbers and display the results. Prompt for each number on a separate line. The second part will prompt for five double numbers and find the average of those numbers. Use plenty of comments in the source code with ample spacing and indentation. 4.) Calculate Amps and Power. Write a C# program that prompts the user for a two double-type variables, namely, voltage (V) and resistance (R) and calculate the current in amperes (I). Use all floating-point numbers and variables. Also calculate and show the power dissipation (P). Recall Ohms Law is I=V/R, where I is current in amps, V is voltage and R is resistance. Also, use P=I2R for the power calculation.

Course Roadmap and Homework Assignments for C#


Updated on 01/03/2009

5.)

Calculate MPH. Write a C# program that inputs double type variables for distance traveled and time, in hours. Use these two variables to calculate miles per hour for a trip. Hint: velocity (mph) = distance / time. Calculate Square Feet and Acres. Prompt the user for a number of square miles and calculate the number of acres and square feet. One acre of land is equivalent to 43,560 square feet. A square mile has 640 acres. Prompt for input data, calculate the answers, and then terminate. Use a C# constant for the 43,560 square feet. Area and Radius of a Circle. Write a C# program that prompts the user for a radius of a circle and prints the circles diameter, circumference and area. Use the constant value 3.14159 for and set it as a C# constant. Hint: Circumference of a circle is found by using d and the area of a circle is r2. Display Size of Data Types: Write a C# program to display the individual size of integers, floats, shorts, unsigned integers, doubles, signed longs, unsigned longs and characters on your particular computer system. Use the C# sizeof() function.

6.)

7.)

8.)

Chapter 4 Problems 9.) Gas Mileage: Write a class separate from the main class that instantiates a separate Gas Class that will calculate gas mileage and cost per mile for a vehicle. Prompt the user for the total gallons purchased, cost of the fill-up and the total miles driven. Then display the miles per gallon (MPG) and cost per mile (CPM). Use different methods for each variable that is entered. For example, a getMilesDriven() method, a getCost() method, a getGallons() method, a displayMPG() method, displayCPM() method, etc. Note: MPG can be found by dividing miles driven by gallons consumed. CPM can be obtained by dividing cost by miles driven. Use the C# numeric format class for a nice clean look. 10.) Average Rainfall: Write a separate class from the main class that instantiates a separate Rainfall Class to calculate average rainfall for three months. Prompt the user for three month string names such as July, August and September, and then the rainfall for each of those three months. Then print an output line that looks something like: The average rainfall for July, August and September is 3.22 inches. Use a getMonth() method and a getRainFall() method to prompt for the class level string and double variables. In other words, call the getMonth() method three times loading three different variables. Temperature Conversion. Write a C# program that performs temperature conversions. It should convert Fahrenheit to Celsius and Celsius to Fahrenheit. Prompt the user for the conversion direction and the temperature. Use a method to get input, a method to convert from C to F and a method to convert from F to C. Do NOT accept values less than 273 Celsius or 459 Fahrenheit. Hint: F = 9.0/5.0 (C) + 32.0, and C = 5.0/9.0 (F 32.0).

11.)

Chapter 5 Problems 12.) Geometry Calculator: Devise a C# program that displays a menu as follows: Prompt for a menu choice and then prompt for input values based on the shape Course Roadmap and C# Programming Problems CSC162AD
1 - Calculate the area of a 2009 Copyright circle 2 - Calculate the area of a rectangle Page 2 3 - Calculate the area of a triangle 4 - Quit

Course Roadmap and Homework Assignments for C#


Updated on 01/03/2009

that was selected from the menu. If the user enters a 1, then you should prompt for a radius. If the user enters 2, then prompt for length and width. If the user enters 3, then prompt for base and height. Test for negative values and do not accept them. Hint: area of a right triangle is (base times height). This problem should have four methods at a minimum, namely, getCircle(), getTriangle(), getRectangle() and displayResults(). 13.) State Abbreviations: Write a C# program that asks the user to enter the following five state abbreviations such as NC, AL, GA, FL or OH. When each abbreviation is typed in, the program should print out the corresponding state name such as Alabama or Ohio. Make sure to account for both uppercase and lowercase abbreviations. Hint: Use the C# string class and an if-else structure. You only need to do these five states, NOT all 50. Use methods to get the month like getMonth(); Math Tutor: Write a C# program to generate 2 random numbers and display those to numbers. Prompt the user for the total and compare it against the calculated total found by the C# program. Hint: use the C# random method, random.Next(). Use your own custom methods to get the numbers and display the results. Date Class: Design a separate class from the main class named MyDate. This class should store a date into three integer variables, namely, month, day and year, all private variables. There should be methods to print the date in the following three formats: 03/29/08 and March 29, 2008 and 29 March 2008. Add a getDate() method, as well. Hypotenuse of a Right Triangle. Write a C# program that has a method that computes the hypotenuse of two sides of a right triangle. The program should print the two sides entered and the hypotenuse. Hint: h = sqrt(a2 + b2 ) where a and b are the two adjacent sides. Use two methods in this program. One method should be called to prompt for the triangle side lengths. Use another method to compute and print the result. Pass the two sides as arguments to the methods. Lesser of Two Numbers. Devise a C# program that contains a method that returns the lesser of two numbers entered from the keyboard. Call the method passing the two numbers entered and pass back the result. Keep prompting until the user enters zero for both parameters. Here is the method prototype: float min(float x, float y); Password Criteria. Imagine you are developing a software package that requires users to enter their own passwords. Your software requires that users passwords meet the following criteria: Passwords should be at least 6 characters long Passwords should contain at least one numeric digit Passwords should contain at least one Upper case character

14.)

15.)

16.)

17.)

18.)

Write a C# program to prompt for a password and test for the criteria above. If the password criterion is not met, then display a message stating what the problem was and prompt again. Problems for Chapter 6 19.) Display ASCII Character Set. Create a C# program to display the ASCII character set from 32 to 100 and then from 225 to 255. Show the decimal value, the character equivalent and the hex value. Your output should look similar to the following: (What happens if you start your loop at zero rather than 32?) Course Roadmap and C# Programming Problems CSC162AD Copyright 2009 Page 3

Course Roadmap and Homework Assignments for C#


Updated on 01/03/2009

Dec Char Hex -------------032 20 033 ! 21 034 " 22 035 # 23 036 $ 24 037 % 25 038 & 26 039 ' 27 040 ( 28 041 ) 29 042 * 2a 043 + 2b 044 , 2c 045 2d 046 . 2e 047 / 2f 048 0 30 049 1 31 050 2 32 051 3 33 052 4 34 053 5 35 054 6 36

20.)

Force Variable Overflow. Write a C# program that forces an overflow condition of a short integer variable on your computer. Keep in mind that some compilers and computer combinations use 1byte short integers while others use 2-byte integers. You need to determine the size of a short integer on your machine. Document your code with plenty of C# comments. Hint: initialize a short integer with 32760 and loop ten times incrementing and displaying the integer variable. Show Me The Money. Write a C# program to calculate how much you would earn if someone offered to pay you a penny a day doubling every day for 30 days. In other words, a penny the first day, two cents the second day, 4 cents the 3rd day, 8 cents the next day, 16 cents the next day, etc, for 30 days. Would you take this job of offered?

21.)

Asterisk Pattern. Write a C# program that prints a pattern similar to the following pattern. Start at 1 and end with 26, however. The middle row of asterisks should be 26. Document your code with comments. * ** *** **** ***** ****** ******* ****** ***** **** *** Course Roadmap and C# Programming Problems Copyright 2009 CSC162AD Page 4

22.)

Course Roadmap and Homework Assignments for C#


Updated on 01/03/2009

** * 23.) Simple Interest. Write a C# program that loops and prints a table of simple interest calculations. Prompt the user for the principal (p), interest rate (r) and time (t) in years. Use a loop from 1 to years entered and calculate interest rate compounded annually for the years selected. Hint: each line uses the formula, i=pr. Time is held to 1 year for each iteration. Hence, the output should look very close to the following:
Enter original deposit amount: 50000 Enter annual interest rate (10% as 10):7 Enter years to save this deposit amount: 18 Year Rate Amount Interest New Amt =============================================== 1 0.07 50000.00 3500.00 53,500.00 2 0.07 53500.00 3745.00 57,245.00 3 0.07 57245.00 4007.15 61,252.15 4 0.07 61252.15 4287.65 65,539.80 5 0.07 65539.80 4587.79 70,127.59 6 0.07 70127.59 4908.93 75,036.52 7 0.07 75036.52 5252.56 80,289.07 8 0.07 80289.07 5620.24 85,909.31 9 0.07 85909.31 6013.65 91,922.96 10 0.07 91922.96 6434.61 98,357.57 11 0.07 98357.57 6885.03 105,242.60 12 0.07 105242.60 7366.98 112,609.58 13 0.07 112609.58 7882.67 120,492.25 14 0.07 120492.25 8434.46 128,926.71 15 0.07 128926.71 9024.87 137,951.58 16 0.07 137951.58 9656.61 147,608.19 17 0.07 147608.19 10332.57 157,940.76 18 0.07 157940.76 11055.85 168,996.61 Interest gained over 18 years is $118,996.61 Mean interest per year is $6,610.92

Show the total interest paid for the life of the loan and show the average interest gained each year. 24.) Factorial. Write a C# program that computes the factorial of a number that is input from the keyboard. A factorial is the product of all the numbers up to the number entered. For example, 6factorial is 720 because 6*5*4*3*2*1 is 720. Six-factorial is written 6! Prompt the user for the numeric input. Keep prompting for values until a zero value is entered. Looping Madness. Write a C# program that loops using the do-loop, while-loop and the for-loop. Each loop should start at n=10 and loop 20 times displaying n and n2, n3 and n4. Create this loop using each of our loop formats; while, do and for. Make sure to properly format the numbers. Lowest Score Drop: Devise a C# program to loop and prompt for 10 test scores. The program needs one method, namely getValues(). The object of the program is to prompt for 10 scores and drop the lowest score and find the average of the last 9 scores. Do all the min and max logic in the getValues() method.

25.)

26.)

Course Roadmap and C# Programming Problems CSC162AD

Copyright 2009 Page 5

Course Roadmap and Homework Assignments for C#


Updated on 01/03/2009

27.)

Math Class: Design a C# class that will do basic math. It should have methods to add, subtract, multiply and divide the 2 arguments passed to it. You will need a method to prompt for the two input values, as well.

Chapter 7 Problems 28.) The Matrix Not the Movie. Write a C# program that declares a 6 by 10 matrix of integers. Initialize each element of the matrix by using the random number method, random.Next() to loop and load random numbers. Have the program print the initial values and the values doubled. Make the displayed output look nice. You can use one method to display the data both times. Hint: Use the C# random.Next() method to load the matrix.
Load the Matrix 5320 9745 6246 199 5919 8514 4075 4389 2298 724 1403 9046 7571 4316 8986 2766 9289 1943 Matrix 10640 398 8150 1448 15142 5532 Times 19490 11838 8778 2806 8632 18578 3263 1670 3279 9677 6203 2667 4862 1884 3763 129 3285 3662 189 4332 6832 126 1601 5560 8180 6500 3268 3479 957 725 6736 2670 2555 372 8010 9142 8198 5615 1515 7511 1000 2929 5839 5919 2154 4074 5256 2497

Two 12492 6526 17028 3340 4596 6558 18092 19354 17972 12406 3886 5334

9724 378 16360 13472 16396 11678 3768 8664 13000 5340 11230 11838 7526 13664 6536 5110 3030 4308 258 252 6958 744 15022 8148 6570 3202 1914 16020 2000 10512 7324 11120 1450 18284 5858 4994

29.)

Sentence Madness. Write a C# program to enter a sentence into a character array. Print the sentence the way it was originally entered and then print it in reverse order. Convert the entire sentence to uppercase and print that result. Convert the entire sentence to lowercase and print that result, as well. Finally, make the first character of the sentence uppercase and print that result. Prompt the user to continue or not with another sentence. Continue looping and asking for sentences until the user types in the appropriate stop character of your choice. Binary to Decimal Conversion. Develop a C# program that prompts the user for a binary string value. Convert the binary string value to a decimal value (base-10) and print out both the decimal value and the binary value. Keep prompting for binary values until a zero value or some other sentinel character is entered. Input and output should look similar to the following: (Hint, use a character array for the binary input and loop backwards.)
Binary to Decimal Conversion Utility Enter any binary number: 111 111 in binary is 7 Decimal Enter any binary number: 1001 1001 in binary is 9 Decimal Enter any binary number: 1111100000111 1111100000111 in binary is 7943 Decimal Enter any binary number: 0 0 in binary is 0 Decimal

30.)

Course Roadmap and C# Programming Problems CSC162AD

Copyright 2009 Page 6

Course Roadmap and Homework Assignments for C#


Updated on 01/03/2009

31.)

Statistics and Array Sorting. Write a C# program to randomly generate 10,000 integers and build an array with the generated numbers. Use the C# random number system method. Determine the largest number and the smallest number in the array. Determine the mid-point of the sorted array, which is the median. Also, find the average of all the numbers in the array. Print the first 10 and last 10 elements of the sorted array. Output should look something like:
Statistical Max: Min: Mean: Median: Measure 93233 12234 54210 54230

First 10 of the Array 12234 13234 14234 23444 27333 Last 10 of the Array 87123 88237 89345 90123 93233

Chapter9 ProblemsWindows Programming)


32.) Modern Stats Engine. This project entails building a nice GUI driven statistics application. At a high level, the program prompts for a series of numbers, does some mathematics on the numbers and displays the results. Write a small C# GUI application that prompts for a bunch of numbers in a textbox, say 10 or 20. See panel on the right for example component layout. Your design can be different.

Calculate max, min, sum, mean, and median of the set of input numbers Modular design. Each calculation should be in its own method; getMean() for example Possible choice of classes are Main class, Utility Class for input and output and Calc Class Add events to the buttons, textbox Add a KeyStroke event to the textbox to detect the enter-key (same as the Add Button) Add a StatusBar component to the bottom with current data and time elements Chapter 10 Problems -- Inheritance 33.) Short Paper. Do some research on C# inheritance and write a one page paper on the benefits of inheritance and the problems that inheritance introduces. Use books, the Internet, etc to find your sources. Add a nice cover page and single space the text. Impress me. Course Roadmap and C# Programming Problems CSC162AD Copyright 2009 Page 7

Course Roadmap and Homework Assignments for C#


Updated on 01/03/2009

34.)

Inheritance 101. Remove all the math functions from the statistics project above (prob-32) and place them in a separate StatsFactory class. Then reengineer the Stats program to inherit the StatsFactory class and its methods. Use plenty of XML type comments in your code especially the method descriptions in the StatsFactory class.

Chapter 11 Problems -- Exceptions 35.) C# Identifier Tester. Write a C# class that prompts for variable names that would be used in C#. Your class should have a method that validates the identifier with the standard C# variable naming conventions we have already learned. The method, isValid(), should be passed a string variable name and return a Boolean true or false depending on the state of the variable name. Now, the tricky part is you need to design a custom error handler that throws an exception whenever an invalid variable name is detected. When the exception is triggered return a false to the calling test harness program. Chapter 12 Problems File I/O 36.) Paragraph Parsing. Go to my website and download the file named paragraph.txt to your PC. Write a program to read in the downloaded text file named paragraph.txt and copy it to a different file using a name that you prompt for at run-time. While copying the file, count the characters, lines, periods, words and spaces. Notice something special between the number of words and number of spaces. Prompt the user for the input and output filenames. Output should look something like the following, but not exactly:
Words: Periods: Spaces: Lines: Characters: 221 17 24 19 1290

37.)

Array Searching. Write a C# program to prompt the user for a State abbreviation, such as AZ, TX, CA, etc. Load an array of state names and their corresponding abbreviations. Display the actual state name based on the abbreviation that was typed in. You will need to surf the Internet to find all the state abbreviations or you can download a file from my website named States.csv. The file is a comma-separated-file with state-name first, a comma, then the state abbreviation. Keep prompting for abbreviations until you enter a stop signal such as XX or STOP, etc. Directory Dive. Write a C# program to display all files in the current directory on your computer system. My Editor. Write a simple text editor. Use a RichTextBox component for the main editor component. Add a menu component with an Open, Close, Save, SaveAs and Exit functions.

38.) 39.)

Course Roadmap and C# Programming Problems CSC162AD

Copyright 2009 Page 8

You might also like