Top Banner
Chapter1- Introduction to Computing and Programming PROGRAMMING EXERCISES 1. Write a program that produces the following output. Replace the name Tyler Howard with your name. Hello World! My name is Tyler Howard! /* DisplayName.cs * This program displays a message to the world * containing a person's name. It * gives practice creating a first * program. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DisplayName { class DisplayName { static void Main(string[] args) { Console.WriteLine("Hello World, my name is Tyler Howard!"); Console.ReadKey(); } } } 2. First develop a prototype, and then write a program that displays the name of the programming language discussed in this text. You should be more creative, but one possible design is given here.
45

Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Mar 06, 2018

Download

Documents

trannguyet
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter1- Introduction to Computing and Programming

PROGRAMMING EXERCISES 1. Write a program that produces the following output. Replace the name Tyler Howard with your name. Hello World! My name is Tyler Howard! /* DisplayName.cs * This program displays a message to the world * containing a person's name. It * gives practice creating a first * program. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DisplayName { class DisplayName { static void Main(string[] args) { Console.WriteLine("Hello World, my name is Tyler Howard!"); Console.ReadKey(); } } } 2. First develop a prototype, and then write a program that displays the name of the programming language discussed in this text. You should be more creative, but one possible design is given here.

Page 2: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

3. Print your name, school, and the year you plan to graduate. Place your name on one line and your graduation year on the second line. Be sure to include appropriate labels. For example, my information would look like the following, if I planned to graduate in 2017: Name: Barbara Doyle Graduation Year: 2017 School: Jacksonville University 4. Develop an application that produces a banner containing information about your project. Items you might include are your programming assignment number, name, date submitted and the purpose of the application. Label each item. These are items you might want to include as internal documentation on future programming assignments. Your output for your banner might look similar to the following: ********************************************************* ** Programming Assignment #4 ** ** Developer: Alma King ** ** Date Submitted: September 17 ** ** Purpose: Provide internal documentation. ** ********************************************************* In addition to printing the output screen banner shown in the preceding code segment, be sure to include appropriate comments as internal documentation to your program.

Flags are a symbol of unity and invoke special meaning to their followers. Create a design for a flag, and write a program that displays your design. One possible design follows. *******—————————————————————————————————— *******—————————————————————————————————— *******—————————————————————————————————— *******—————————————————————————————————— ————————————————————————————————————————— —————————————————————————————————————————

Page 3: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

6. Create an application that produces three different outputs using the same phrase. Select your own favorite popular saying for the phrase. The phrase should first be displayed on one line. Use at least three Write( ) methods - but the output should all appear on a single line. Then print the phrase on three lines, again using only Write( ) methods. For your third and final output, print your favorite saying one word per line. Decide which combination of Write( ) and/or WriteLine( ) would be the most streamlined approach. Following is an example of what the final output would look like using a favorite saying of the author:

7. Produce a listing containing information about you. Include items such as, your name, hometown, major, hobby and/or favorite activity. Label each piece of information, place each of the items on separate lines and place a backslash (\) after each entry. Begin and end the entire listing with the | character. Include the full listing in a box of asterisks. Your output might look similar to the following:

8. Hangman is a favorite childhood game. Design the stick figure for this game and produce a printed listing with your stickman. One possible design follows. You may implement this design or develop an improved version. (^;^) | ./ | \. | _/ \_

Page 4: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming
Page 5: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

9. Create an application that displays the following patterns. You may use any character of your choice to construct the pattern. One possible solution follows.

10. Write your initials in block characters to a standard output device. Design your prototype using the symbol(s) of your choice. For example, my initials in block characters are shown below. BBBBBBBBBBBBBB AA DDDDDDDDDDDDDDDDD BB BB AA AA DD DD BB BBBB AA AA DD DD BB BB AA AA DD DD BB BB AA AA DD DD BBBBBB AA AA AA AA AA AA DD DD BB BB AA AA DD DD BB BB AA AA DD DD BB BBBB AA AA DD DD BB BB AA AA DD DD BBBBBBBBBBBBBBB AA AA DDDDDDDDDDDDDDDDD

Page 6: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter2. Data Types and Expressions

PROGRAMMING EXERCISES For each of the exercises, be sure to include appropriate comments, choose meaningful identifiers, and use proper indentations in your source code. 1. Design an application that converts miles to feet. Declare and initialize miles to 4.5. Show your miles formatted with two positions to the right of the decimal. Feet and inches should both be shown with no positions to the right of the decimal. Once you get that portion running, modify your solution so that you also show the total number of inches. Go into your source code and change the initialization value for miles. Rerun the application. 2. Write a program that converts a mile into its equivalent metric kilometer measurement. Test the program by performing a compile-time initialization of 10 for the miles value. Display the original miles and the formatted converted value. Go into your source code and change the initialization value and rerun the application with a new mile value of 3.5. For an additional challenge, include in your application a kilometer to miles converter. 3. Write a program that converts a temperature given in Celsius to Fahrenheit. Test the program by performing a compile-time initialization of 32 for the original Celsius value. Display the original temperature and the formatted converted value. Go into your source code and change the initialization value to 0. Rerun the application. Select additional test values and rerun the application. 4. Write a program that shows the formatted retail price of items when there is a 15% markup. Test the program by performing a compile-time initialization with Ruggy Shoes, which has a wholesale price of $52.00. Display appropriately2 labeled retail and wholesale values for the shoes. Once you get that running, go back into your source code, add lines of code that will reassign the memory location’s values for a Teno Jacket, which has a wholesale price of $71.00. Add additional lines of code, which will display the new information. 5. Write a program that calculates and prints the take-home pay for a commissioned sales employee. Perform a compile-time initialization and store the name of Nesbith Lang in a variable called employeeName. Nesbith earns 7% of her total sales as her commission. Her federal tax rate is 18%. She contributes 10% to a retirement program and 6% to Social Security. Her sales this month were $161,432. Produce a formatted report showing the amount for each of the computed items. Select appropriate constants. After you finish displaying Nesbith Lang’s data, change the values and rerun the application. 6. Write a program that computes the average of five exam scores. Declare and

Page 7: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

perform a compile-time initialization with the five values. Use a constant to define the number of scores. Print all scores and the average value formatted with no digits to the right of the decimal. Rerun the application with different values. 7. Write a program that prints the number of quarters, dimes, nickels, and pennies that a customer should get back as change. Run your program once by performing a compile-time initialization using 92 cents for the value to be converted. Go into your source code and change the 92 to 27. Rerun the application. 8. Write a program that computes a weighted average giving the following weights. Homework: 10% Projects: 35% Quizzes: 10% Exams: 30% Final Exam: 15% Do a compile-time initialization with the following values: Homework: 97; Projects: 82; Quizzes: 60; Exams: 75; Final Exam 80. Display all values, including the weights, appropriately labeled and formatted. Rerun the application with different values. 9. Write a program that computes the amount of money the computer club will receive from the proceeds of their granola project. Each case has 100 bars. The granola bars sell for $1.50 per bar. Each case costs $100.00. They are required to give the student government association 10% of their earnings. Display their proceeds, showing the amount given to the student government association. Show all the values formatted with currency. Do a compile-time initialization using 29 for cases sold.

10. In countries using the metric system, many products are sold by grams and kilograms as opposed to pounds and ounces. Write an application that converts grams to pounds and will display the price of the product by pound. Test your application by doing a compile-time initialization of a product called Montreal Smoked Meat, which sells for $2.09 per 100 grams.

Page 8: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter3. Methods and Behavior

PROGRAMMING EXERCISES 1. Write an application that includes two additional methods in addition to the Main( ) method. One method should return a string consisting of four or five lines of information about your school. The other method should return a string consisting of asterisks. First call the method that returns the string of asterisks. Call the method that returns the asterisk a second time after you invoke the method that displays the information about your school. Items you might include are the name of your school, number of students enrolled, and school colors. Include appropriate labels. The display should be aesthetically pleasing so include enough asterisks to surround your listing. 2. Design a message display application. Allow users to enter their name and favorite saying in a single method that gets invoked two times. First call the method asking for the person’s name. Send a string argument indicating what value should be entered. Invoke the method a second time to retrieve the favorite saying. Return the string values back to the Main( ) method. Call another method, sending the name and saying. From that method, display the message showing the person’s name and their saying surrounded by rows of greater than/less than symbols(<><><>). 3. Write an application that allows a user to input the height and width of a rectangle and output the area and perimeter. Use methods for entering the values, performing the computations, and displaying the results. Results should be formatted and printed in a tabular display. 4. Design an application using methods that convert an integer number of seconds to an equivalent number of hours, minutes, and seconds. Use methods for entering the initial seconds, performing the computations, and displaying the results. Results should be formatted and printed in a tabular display. 5. Write a program that converts a temperature given in Fahrenheit to Celsius. Allow the user to enter values for the original Fahrenheit value. Display the original temperature and the formatted converted value. Use appropriate methods for entering, calculating, and outputting results. 6. Write a program that can be used to convert meters to feet and inches. Allow the user to enter a metric meter value in a method. Write appropriate methods for your solution.

7. Write a program that can be used to determine the tip amount that should be added to a restaurant charge. Allow the user to input the total, before

Page 9: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

taxes and the tip percentage (15% or 20%). Produce output showing the calculated values including the total amount due for both the 15% and the 20% tips. Tax of 9% should be added to the bill before the tip is determined. Write appropriate methods for your solution. 8. Write a program that computes the amount of money the computer club will receive from proceeds of their granola bar sales project. Allow the user to enter the number of cases sold and the sale price per bar. Each case contains 12 bars; each case is purchased at $5.00 per case from a local vendor. The club is required to give the student government association 10% of their earnings. Display their proceeds formatted with currency. Write appropriate methods for your solution. 9. Write a program that calculates and prints the take-home pay for a commissioned sales employee. Allow the user to enter values for the name of the employee and the sales amount for the week. Employees receive 7% of the total sales. Federal tax rate is 18%. Retirement contribution is 15%. Social Security tax rate is 9%. Use appropriate constants. Write input, display, and calculation methods. Your final output should display all calculated values, including the total deductions and all defined constants. 10. Write an application that helps landowners determine what their property tax will be for the current year. Taxes are based on the property’s assessed value and the annual mileage rate. The established mileage rate for the current year is $10.03 per $1000 value. Homeowners are given a $25,000 tax exemption, which means they may subtract $25,000 from the assessed value prior to calculating the taxable value. Enable users to enter the property address and the prior year’s assessed value. The township has decided to increase all properties’ assessed value 2.7% for the current year to add additional monies to the school budget line. Provide methods to compute and return the new assessed value and the proposed taxes for the current year. Provide another method that displays the formatted values.

Page 10: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter4. Creating your own classes

PROGRAMMING EXERCISES 1. Create a class representing a student. Include characteristics such as student number, first and last name, overall GPA, classification, andmajor. Write at least two constructors. Include properties for each of the data items. Create a second class that instantiates the first class with information about yourself. In the second class, create a class method that displays your name and GPA. 2. Create a Motorway class that can be used as extra documentation with directions. Include data members such as name of motorway, type (i.e., Road, Street, Avenue, Blvd., Lane, etc.), direction (i.e., E, W, N, or S), surface (i.e., blacktop, gravel, sand, concrete), number of lanes, toll or no toll, and the party that maintains it. Write instance methods that returns the full name of the motorway, full name of the motorway and whether it is toll or not, and full name of the motorway and the number of lanes. Also include a ToString( ) method that returns all data members with appropriate labels. Include enough constructors to make the class flexible and experiment with using the class diagram to create the property members.

3. Create an Employee class. Items to include as data members are employee number, name, date of hire, job description, department, and monthly salary. The class is often used to display an alphabetical listing of all employees. Include appropriate constructors and properties. Override the ToString ( ) method to return all data members. Create a second class to test your Employee class. 4. Create a Receipt class that could be used by an automobile parts store. Items to include as data members are receipt number, date of purchase, customer number, customer name and address, customer phone number, item number, description, unit price, and quantity purchased. For simplicity you may assume each receipt contains a single item number. Include appropriate constructors and properties plus an additional method that calculates the total cost using the quantity and unit price. Override the ToString ( ) method to return the information about the customer (name and phone number) and the total cost of the item purchased. Create a second class to test your Receipt class. 5. Create a Date class with integer data members for year, month, and day. Also include a string data member for the name of the month. Include a method that returns the month name (as a string) as part of the date. Separate the day from the year with a comma in that method. Include appropriate constructors, properties, and methods. Override the ToString ( ) method to display the date formatted with slashes (/) separating the month, day, and year. 6. Create a Trip class. Include as data members destination, distance traveled,

Page 11: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

total cost of gasoline, and number of gallons consumed. Include appropriate constructors and properties. Add additional methods that calculates miles per gallon and the cost per mile. Override the ToString ( ) method. Create a second class to test your Trip class. 7. Create a Money class that has as data members dollars and cents. Include IncrementMoney and DecrementMoney instance methods. Include constructors that enable the Money class to be instantiated with a single value representing the full dollar/cent amount as well as a constructor that enables you to create an instance of the class by sending two separate integer values representing the dollar and cent amounts. Include an instance method that returns as a string the number of dollars, quarters, nickels, dimes, and pennies represented by the object’s value. Override the ToString( ) method to return the monetary amount formatted with currency symbols. Create a second class to test your Money class.

8. There are a number of national and state parks available to tourists. Create a Park class. Include data members such as name of park, location, type of (i.e., national, state, local) facility, fee, number of employees, number of visitors recorded for the past 12 months, and annual budget. Write separate instance methods that a) return a string representing name of the park, the location and type of park; b) return a string representing the name of the park, the location and facilities available; c) compute cost per visitor based on annual budget and the number of visitors during the last 12 months; and d) compute revenue from fees for the past year based on number of visitors and fee. Also include a ToString( ) method that returns all data members with appropriate labels. Create a second class to test your Park class. 9. Write a program that includes an Employee class that can be used to calculate and print the take-home pay for a commissioned sales employee. All employees receive 7% of the total sales. Federal tax rate is 18%. Retirement contribution is 10%. Social Security tax rate is 6%. Write instance methods to calculate the commission income, federal and social security tax withholding amounts and the amount withheld for retirement. Use appropriate constants, design an object-oriented solution, and write constructors. Include at least one mutator and one accessor method; provide properties for the other instance variables. Create a second class to test your design. Allow the user to enter values for the name of the employee and the sales amount for the week in the second class. 10. Write a program that creates a ProfessorRating class consisting of professor ID and three ratings. The three ratings are used to evaluate easiness, helpfulness, and clarity. In a separate implementation class, allow the user to enter the values. Call the constructor to create an instance of the ProfessorRating class. Include appropriate properties. Do not allow the ID to be changed after an object has been constructed. Provide a method in the ProfessorRating class to compute and return the overall rating average. Print all ratings and the average rating formatted with

Page 12: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

no digits to the right of the decimal from the implementation class. Use a single class method to enter all data.

Page 13: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter5. Making Decisions

PROGRAMMING EXERCISES 1. Write an application that will enable you to display an aquarium’s pH level. The pH is a measure of the aquarium water’s alkalinity and is typically given on a 0-14 scale. For most freshwater fish tanks, 7 is neutral. Tanks with a pH lower than 7 are considered acidic. Tanks with a pH higher than 7 are alkaline. Allow the user to input the pH level number. Display a message indicating the health (i.e., acidic, neutral, or alkaline) of the aquarium. 2. Create a Month class that has a single data member of month number. Include a member method that returns the name of the month and another method that returns the number of days in the month. The ToString( ) method should return the name and number of days. Write a second class to test your Month class. The second class should allow the user to input a month number. Display the name of the month associated with the number entered and the number of days in that month. For this exercise, use 28 for February. If the user inputs an invalid entry, display an appropriate message.

Write a program to calculate and display a person’s Body Mass Index (BMI). BMI is an internationally used measure of obesity. Depending on where you live, either use the Imperial BMI formula or the Metric Imperial Formula. Once the BMI is calculated, display a message of the person’s status. Prompt the user for both their weight and height. The BMI status categories, as recognized by the U.S. Department of Health & Human Services, are shown in the table below: BMI Weight Status Below 18.5 Underweight 18.5 - 24.9 Normal 25 - 29.9 Overweight 30 & above Obese 4. Write a program that calculates the take-home pay for an employee. The two types of employees are salaried and hourly. Allow the user to input the employee first and last name, id, and type. If an employee is salaried, allow the user to input the salary amount. If an employee is hourly, allow the user to input the hourly rate and the number of hours clocked for the week. For hourly employees, overtime is paid for hours over 40 at a rate of 1.5 of the base rate. For all employees’ takehome pay, federal tax of 18% is deducted. A retirement contribution of 10% and a Social Security tax rate of 6% should also be deducted. Use appropriate constants. Design an object-oriented solution. Create a second class to test your design.

Page 14: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

5. A large Internet merchandise provider determines its shipping charges based on the number of items purchased. As the number increases, the shipping charges proportionally decrease. This is done to encourage more purchases. If a single item is purchased the shipping charge is $2.99. When customers purchase between 2 and 5 items, they are charged the initial $2.99 for the first item and then $1.99 per item for the remaining items. For customers who purchase more than 5 items but less than 15, they are charged the initial $2.99 for the first item, $1.99 per item for items 2 through 5, and $1.49 per item for the remaining items. If they purchase 15 or more items, they are charged the initial $2.99 for the first item, $1.99 per item for items 2 through 5, and $1.49 per item for items 6 through 14 and then just $0.99 per item for the remaining items. Allow the user to enter the number of items purchased. Display the shipping charges. 6. Write an application that computes the area of a circle, rectangle, and cylinder. Display a menu showing the three options. Allow users to input which figure they want to see calculated. Based on the value inputted, prompt for appropriate dimensions and perform the calculations using the following formulas: Area of a circle = pi * radius2 Area of a rectangle = length * width Surface area of a cylinder = 2 * pi * radius * height + 2 * pi * radius2 Write a modularized solution, which includes class methods for inputting data and performing calculations.

Create an application with four classes. Three of the classes should contain data and behavior characteristics for circle, rectangle, and cylinder. The fourth class should allow the user to input a figure type from a menu of options. Prompt for appropriate values based on the inputted figure type, instantiate an object of the type entered, and display characteristics about the object. 8. Design a solution that prints the amount of profit an organization receives based on it sales. The more sales documented, the larger the profit ratio. Allow the user to input the total sales figure for the organization. Compute the profit based on the following table. Display the sales and profit formatted with commas, decimals, and a dollar symbol. Display the profit ratio formatted with a percent symbol. 0 - $1000: 3% $1000.01_$5000: 3.5% $5000.01_$10000: 4% over $10000: 4.5% Be sure to design your solution so that all possible situations are accounted for and tested. Use the decimal data type for your solution. What values did you enter and test to verify your program’s correctness? 9. Two fuel stops, CanadianFuel and AmericanFuel, are positioned near the U.S.– Canadian border. At the Canadian station, gas is sold by the liter. On the

Page 15: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

American side, it is sold by the gallon. Write an application that allows the user to input information from both stations and make a decision as to which station offers the most economical fuel price. Test your application with 1.259 per liter against 4.50 per gallon. Once the decision is made, display the equivalent prices. 10. Write a program that takes a decimal value between 1 and 10 and displays its equivalent roman numeral value. Display an error message if the value entered is outside of the acceptable range. Write a two class solution. The second class should allow the user to input a test value.

Page 16: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter6. Repeating Instructions

PROGRAMMING EXERCISES 1. Write a program that generates 1000 random numbers between 0 and 100000. Display the number of odd values generated as well as the smallest and the largest of values. Output should be displayed in a Windows message box. 2. Create an application that contains a loop to be used for input validation. Valid entries are positive integers less than 100. Test your program with values both less than and greater than the acceptable range as well as non-numeric data. When the user is finished inputting data, display the number of valid and invalid entries entered. 3. Write a program to calculate the average of all scores entered between 0 and 100. Use a sentinel-controlled loop variable to terminate the loop. After values are entered and the average calculated, test the average to determine whether an A, B, C, D, or F should be recorded. The scoring rubric is as follows: A—90-100; B—80-89; C—70-79; D—60-69; F < 60.

4. Create an application that determines the total due including sales tax and shipping. Allow the user to input any number of item prices. Sales tax of 7.75% is charged against the total purchases. Shipping charges can be determined based on the number of items purchased. Use the following chart to determine the shipping charge. Display an itemized summary containing the total purchase charge, number of items purchased, sales tax amount, shipping charge, and grand total. fewer than 3 items $3.50 3 to 6 items $5.00 7 to 10 items $7.00 11 to 15 items $9.00 more than 15 items $10.00 5. Write a program that allows the user to input any number of hexadecimal characters. Sum the values and display the sum as a hexadecimal value. Within the loop, convert each character entered to its decimal equivalent. Treat each single inputted character as a separate value. Display the original hex value and the corresponding decimal value. For example, if the user inputs F, 15 would be displayed as the decimal equivalent. Use a sentinel value to control the loop. After all values are entered, display the sum of values entered in both hexidecimal and decimal notation. 6. Write an application that will enable a vendor to see what earnings he can expect to make based on what percentage he marks up an item. Allow the user to input the wholesale item price. In a tabular form, show the retail price of the item marked up at 5%, 6%, 7%, 8%, 9% and 10%.

Page 17: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

7. Write a program that produces a multiplication table with 25 rows of computations. Allow the user to input the first and last base values for the multiplication table. Display a column in the table beginning with the first base inputted value. The last column should be the ending base value entered. The first row should be for 1 times the beginning base, 1 times the (beginning base value + 1), through 1 times the ending base value. The last row should be for 25 times the beginning base, 25 times the (beginning base value + 1), through 25 times the ending base value. Base values can range from 2 through 8. Display an error message if an invalid base is entered. Display an aesthetically formatted multiplication table. An example of output produced when 2 and 8 are entered appears in Figure 6-22.

8. Prompt the user for the length of three line segments as integers. If the three lines could form a triangle, print the integers and a message indicating they form a triangle. Use a state-controlled loop to allow users to enter as many different combinations as they want. 9. Write an application that calculates a student’s GPA on a 4.0 scale. Grade point average (GPA) is calculated by dividing the total amount of grade points earned by the total amount of credit hours attempted. For each hour, an A receives 4 grade points, a B receives 3 grade points, a C receives 2 grade points, and a D receives 1 grade point. Allow the user to input any number of courses and associated grades. Display the number of hours earned and the GPA.

Page 18: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter7. Arrays

PROGRAMMING EXERCISES 1. Write a program that reads data into an array of type int. Valid values are from 0 to 10. Your program should display how many valid values were inputted as well as the number of invalid entries. Output a list of distinct valid entries and a count of how many times that entry occurred. Use the following test data: 1 7 2 4 2 3 8 4 6 4 4 7 2. The Ion Realty Sales Corporation would like to have a listing of their sales over the past few months. Write a program that accepts any number of monthly sales amounts. Display the total of the values. Display a report showing each original value entered and the percentage that value contributes to the total. You may prompt the user for the number of values to be inputted. 3. Write a temperature application. Your solution should be a two class application that has a one-dimensional array as a data member. The array stores temperatures for any given week. Provide constructors for instantiating the class and methods to return the highest temperature, lowest temperature, average temperature, and the average temperature excluding the lowest temperature. Provide a method that accepts as an argument a temperature and returns the number of days the temperatures were below that value. Override the ToString( ) method to return a listing of all the temperatures in three column format and the temperature range for the given week. Write a second class to test your class. 4. Create three arrays of type double. Do a compile-time initialization and place different values in two of the arrays. Write a program to store the product of the two arrays in the third array. Produce a display using the MessageBox class that shows the contents of all three arrays using a single line for an element from all three arrays. For an added challenge, design your solution so that the two original arrays have a different number of elements. Use 1 as the multiplier when you produce the third array. 5. Write a program that allows the user to enter any number of names, last name first. Using one of the predefined methods of the Array class, order the names in ascending order. Display the results. 6. Write a two class application that has as a data member an array that can store state area codes. The class should have a member method that enables users to test an area code to determine if the number is one of the area codes in the state exchange. The member method should use one of the predefined methods of the Array class and return true if the argument to the method is one of the state codes. Override the ToString( ) method to return the full list of area codes with each

Page 19: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

surrounded by parentheses. To test the class, store a list of state codes in a onedimensional array. Send that array as an argument to the class. Your application should work with both an ordered list of area codes or an unordered list.

Page 20: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

7. Write an application that allows the user to input monthly rainfall amounts for one year. Calculate and display the average rainfall for the year. Display the month name along with the rainfall amount and its variance from the mean. 8. 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. 9. Write a program that allows any number of values between 0 and 10 to be entered. When the user stops entering values, display a frequency distribution bar chart. Use asterisks to show the number of times each value was entered. If a given number is not entered, no asterisks should appear on that line. Your application should display error messages if a value outside the acceptable range is entered or if a non-numeric character is entered. 10. Write a two class solution that includes data members for the name of the course, current enrollment, and maximum enrollment. Include an instance method that returns the number of students that can still enroll in the course. The ToString( ) method should return the name of the course, current enrollment, and the number of open slots. Design your solution using parallel arrays. Declare an array of class objects in your implementation class. Test your application with the following data:

Page 21: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter8. Advanced Colletions

PROGRAMMING EXERCISES 1. Write an application that creates and returns a one-dimensional array containing all the elements in the two-dimensional array. Store the values in a row major format. For testing purposes, you may do a compile-time initialization of a 12 x 5 two-dimensional array. Display both the two-dimensional and the one-dimensional array. Be sure the values in the array are number aligned. 2. Write an application that will let you keep a tally of how well three salesmen are performing selling five different products. You should use a two-dimensional array to solve the problem. Allow the user to input any number of sales amounts. Do a compile-time initialization of the salesperson’s names and product list. Produce a report by salesman, showing the total sales per product. 3. Revise your solution for problem 2 so that you display the total sales per salesman. Place the first and last names for the salesmen in an array. Write your solution so that any number of salesmen and any number of products can be displayed. When you display your final output, print the salesman’s last name only, sales for each product, and the final sales for the salesman. After you display the tables of sales, display the largest sales figure indicating which salesman sold it and which product was sold. 4. Write a two class application that creates a customer code to be placed on a mailing label for a magazine. Allow the user to input their full name with the first name entered first. Prompt them to separate their first and last name with a space. Ask for their birthdate in the format of mm/dd/yyyy. Ask for the month (number) they purchased a subscription and ask for their zip code. Your mailing label should contain the last name, followed by their year of birth, the number of characters in the full name, the first three characters of the month they purchased the subscription, and the last two digits of their zip. The code for Bob Clocksom born 01/22/1993, who purchased his subscription during the 10th month of the year and lists 32226 as his zip code would be Clocksom9312Oct26. 5. Write a program that allows the user to enter any number of names. Your prompt can inform the user to input their first name followed by a space and last name. Order the names in ascending order and display the results with the last name listed first, followed by a comma and then the first name. If a middle initial is entered, it should follow the first name. Your solution should also take into consideration that some users may only enter their last name (one name). 6. Write an application that creates a two-dimensional array. Allow the user to input the size of the array (number of rows and number of columns). Fill the array with random numbers between the 0 and 100. Search the array for the

Page 22: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

largest value. Display the array values, numbers aligned, and the indexes where the largest value is stored.

Page 23: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

7. Write a program that creates a two-dimensional array with 10 rows and 2 columns. The first column should be filled with 10 random numbers between 0 and 100. The second column should contain the squared value of the element found in column 1. Using the Show( ) method of the MessageBox class, display a table. 8. reAay ouyay aay hizway ithway igPay atin?Lay? (Translated: ‘‘Are you a whiz with Pig Latin?’’) Write a program that converts an English phrase into a pseudo- Pig Latin phrase (that is Pig Latin that doesn’t follow all the Pig Latin syntax rules). Use predefined methods of the Array and string classes to do the work. For simplicity in your conversion, place the first letter as the last character in the word and prefix the characters ‘‘ay’’ onto the end. For example, the word ‘‘example’’ would become ‘‘xampleeay’’, and ‘‘method’’ would become ‘‘ethodmay.’’ Allow the user to input the English phrase. After converting it, display the new Pig Latin phrase. 9. Write an application that displays revenue generated for exercise classes at the Tappan Gym. The gym offers two types of exercise classes, zumba and spinning, six days per week, four times per day. Zumba is offered at 1, 3, 5, and 7 p.m.; spinning is offered at 2, 4, 6, and 8 p.m. When attendees sign up, they agree to pay $4.00 per class for zumba and $5.00 for spinning. Produce a table displaying the number of attendees per time slot. Display a row and column of totals showing the total number of attendees by day and also time period. Also include a column showing the revenue generated each day and the overall revenue per type of exercise. Do a compile-time initialization of your data structures using data from the following table.

Page 24: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

10. Write an application that enables you to randomly record water depths for 5 different locations at 0700 (7 a.m.), 1200 (noon), 1700 (5 p.m.), and 2100 (9 p.m.). The locations are Surf City, Solomons, Hilton Head, Miami, and Savannah. For ease of input, you may want to code the locations (i.e., Surf City = 1, Solomons = 2, etc.) and code the time (i.e., 0700 = 1, 1200 = 2, etc.). If the same location and time are entered more than one time, store the last value entered into the array. After the data is entered, display the average depth at each location and the average depth by time period.

Page 25: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter 9. Introduction to Windows Programming

PROGRAMMING EXERCISES 1. Create a Windows application that can be used to input a user’s name. Include an appropriate label indicator for the name and a textbox for the input entry. A button labeled OK should retrieve and display the value entered on another label positioned near the bottom of the form. The font color for all objects should be yellow. Change the background color of the form to an appropriate one to use with your yellow text. Change the Font property to a font of your choice. The size of the font for all objects except the Button should be at least 14 points. The Button font should be 16 points. Add a title caption of ‘‘Name Retrieval App’’ to the form. Initially clear the text from the label that will display your final answer. When the OK button is pressed, retrieve the name and concatenate that value with a Congratulatory message. For example, you might display, ‘‘Congratulations, Brenda Lewis, you retrieved the data!’’, if your name was Brenda Lewis. Align the controls so they are aesthetically pleasing. Be sure to change the default names of all controls involved in program statements. 2. Create a Windows application that can be used to change the form color. Your form background color should initially be blue. Provide at least two buttons with two different color choices. Change the font style and size on the buttons. Align the buttons so that they are in the center of the form. The buttons should be the same size. Add event handlers for the buttons so that when the user clicks the button, the form changes color, and a message box is displayed alerting the user as to what color the form is. Be sure to name any controls used in program statements prior to registering your event. Change the default title bar text. Hint: This exercise may require you to do some research. You may want to review the code placed in the .Designer.cs file after you set the form’s initial color. 3. Create a Windows application that contains two textboxes (with labels) and one button. The textboxes should be used to allow the user to input the x- and ycoordinates to indicate where the form should be positioned. When the user clicks the button, the window should be moved to that new point. Be sure to label the textboxes appropriately. Change the form’s background color. Add a title caption to the form. Include a heading above the textboxes and button. Enlarge the size of the font. Only allow positive integers to be used for the coordinates. Hint: One easy way to do this is to set the location using an instance of the Point class when the user clicks the button. To do this, you could allow the user to input values for both x and y into two separate textbox objects. After being retrieved, they would need to be parsed or converted to their integer equivalent. Then use the numeric values for x and y to set the location by typing

Page 26: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Location = new Point(x,y);.

Page 27: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

4. Create a Trip Calculator Windows application that can be used to determine miles per gallon for a given trip. Set the Form object properties of Name, ForeColor, BackColor, Size, Location, Text, and AcceptButton. The form should contain labels and textboxes to allow the user to input trip destination, miles traveled, and gallons of gas consumed. Two buttons should be placed on the form. Name all objects used in program statements. When the user clicks the button that performs the calculations, display in a label the miles per gallon for that trip. The second button should be used to reset or clear textbox entries. 5. Create a Windows application that contains two textboxes and two buttons. The textboxes should be used to allow the user to input two positive numeric values. The buttons should be labeled Add and Multiply. Create event-handler methods that retrieve the values, perform the calculations, and display the result of the calculations on a label. The result label should initially be set to be invisible with a font color of yellow. If invalid data is entered, change the font color to red on the result label and display a message saying ‘‘Value must be numeric and > 0.’’ When the final answer is displayed, the font color should be yellow. Additional labels will be needed for the textboxes captions. Do not allow non-numeric characters to be entered. Invoke the TryParse( ) method to retrieve the values. All controls involved in program statements should be named. Right justify values in the textbox. 6. Create a Windows application that contains a textbox for a person’s name. Plan that the user may enter only first and last name, or they may enter first, middle, and last names. Include labels to store first, middle, and last names. A button should be included. When the button is clicked, retrieve the full name, separate it into first, middle (if present), and last names and then display the labeled name values. 7. Create a Windows application that contains two textboxes and three buttons. One of the textboxes and one of the buttons are initially invisible. The first textbox should be used to input a password. The textbox should be masked to some character of your choosing so that the characters entered by the user are not seen on the screen. When the user clicks the first button, the second textbox and button should be displayed with a prompt asking the user to reenter his or her password. Set the focus to the second password textbox. Now, when the user clicks the second button, have the application compare the values entered to make sure they are the same. Display an appropriate message indicating whether they are the same. Once the check is made, display a third button that resets the form. 8. Create a Windows application that can be used to determine distance traveled given speed and time. Recall that distance = speed * time. Provide textboxes for time and speed and a button to calculate to the distance. Be sure only numeric data is able to be entered into the textboxes. Experiment with the controls’

Page 28: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

properties. Spend time with your design so that your GUI is very user friendly and looks nice.

Page 29: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

9. Create a Windows application that functions like a banking account register. Separate the business logic from the presentation layer. The graphical user interface should allow the user to input the account name, number, and balance. Provide textbox objects for withdrawals and deposits. A button should be available for clicking to process withdrawal and deposit transactions showing the new balance. 10. Create the higher/lower guessing game using a graphical user interface. Allow users to keep guessing until they guess the number. Keep a count of the number of guesses. Choose two colors for your game: one should be used to indicate that the value the users guessed is higher than the target; the other is used to indicate that the value the users guessed is lower than the target. With each new guess, show the guess count and change the form color based on whether the guess is higher than the target or lower. When they hit the target, display a message on a label indicating the number of guesses it took. Several approaches can be used to seed the target: one is to generate a random number by constructing an object of the Random class. For example, the following stores a random whole number between 0 and 100 in target: Random r = new Random(); int target = r.Next(0,101);

Page 30: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter10. Programming based on events

PROGRAMMING EXERCISES 1. Create a graphical user interface that allows the users to enter personal information such as their names, e-mail addresses, and phone numbers. Include a menu that provides a minimum of four features. The first displays the information entered by the user in a message box. The second clears the entries so that new values can be entered, the third menu option displays information about the application such as who developed it and what version it is. Another menu option closes the application. Be creative and be sure to produce an aesthetically pleasing design using options from the Format menu if you are using Visual Studio. 2. Create a Windows application that can be used as a sign-up sheet for ski equipment for the Flyers Sports Club. The club has ski equipment that it makes available to members at a minimal charge. In an attempt to determine what type of equipment members might need for an upcoming trip, they have asked you to design and implement an equipment-needs form. Include CheckBox objects that allow users to select the type of gear they will need to purchase for the trip. Include selections of snow gloves, skis, goggles, earmuffs, and other items you feel are appropriate. Include at least one picture image on your application. After all selections are made, display a message indicating what items have been selected. You will probably want to include menu options to display and clear the order for the next user. Also include an option that enables the user to exit the application. 3. Create a graphical user interface that can be used by a community group to enable youths to sign up for different sporting events. Include radio buttons with five different sport names. Only one of these should be selectable. Program your event-handler method so that a message is displayed with each selection of a different sport. For example, if one of the sports is skiing, the message might say, ‘‘Bring warm clothes!’’ Also include a PictureBox object on the form to display pictures of the sporting event. When the particular sport is selected, make the PictureBox visible. You can find free graphics on the Internet to use in your application. Hint: One way to associate a file to the PictureBox control is to Import an image from the Image property. 4. Create a Message Displayer that has one ComboBox object with a list of at least four of your favorite sayings. In your design, include the capability of letting users enter their own sayings. When a selection is made or a new entry is typed, display the selection on a Label object on your form. Add a menu to the application that includes at least the menu options of Format and Help. Under the Format selection, include options of Font and Color. Wire the Font and Color options to the Windows predefined Font and Color dialog boxes so that when their values are changed, the text in the Label object displaying the saying is changed.

Page 31: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming
Page 32: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

5. Create an order form that allows bags to be purchased. There are six different types: full decorative, beaded, pirate design, fringed, leather, and plain. Create a ListBox object for the different styles. Include a ComboBox for quantity. Quantities up to 10 should be provided. After the user makes a selection, display a message indicating which selection was made. Include an option to clear selections. Provide appropriate error messages when selections are not made. 6. Add to the application in Exercise 5 by including a control that allows the user to determine the type of shipping they desire. Include a set of radio buttons that contain shipping options of overnight, three day, and standard. Add the price for each bag to the listbox selection as follows: full decorative—$50.00; beaded—$45.00; pirate design—$40.00; fringed—$25.00; leather—$80.00; and plain—$20.00. Display the items sorted. Using methods of the string class, retrieve and use the price from the listbox. The shipping charges are based on the total purchase. The following percentages are used: overnight—10%; three day—7%; and standard—5%. Display in a message box the shipping charge along with the selection, quantity, and total cost.

7. The computer club is selling T-shirts. Create an attractive user interface that allows users to select sizes (S, M, L, and XL) and quantity. Which controls would be most appropriate? Remember, the fewer keystrokes required of the user the better. Display the selections made by the user with the Process menu option. Include an option to exit the application. 8. Add to your solution in Exercise 7 by including two more sizes, XSmall and XXLarge. Add statements that process the order by calculating the total cost. Each shirt is $16 except the XSmall and XXLarge; their specialty prices are $20.00 each. Allow users to purchase different sizes on the same order. Include an ‘‘Add to Cart’’ option from the Process menu that enables the user to add multiple selections to the order. Display the total cost for each selection and the final cost for the order. Include a Help menu option that displays instructions. 9. Create aWindows application for purchasing floor covering. Allow the length and width (feet and inches) of a room to be entered. Be sure to include program statements that will keep your program from crashing if they enter nonnumeric characters for the room dimensions. Have a control that displays different types along with the prices of floor covering. Using the tab control, provide selections such as Hardwood, Carpet, and Laminate. On each tab allow the user to select a type and price. Include, for example, options like Oak, Maple, Walnut, and Cherry Hardwood floors with prices such as $34.95 per square yard for Oak and $41.95 per square yard for Cherry. After the users enter their room dimensions and selects the floor covering and price, display the total cost to cover the room. Include an option to clear selections. Place both the type of floor covering and the price in a single control, such as a ComboBox and use string manipulation techniques to strip the price out of the string.

Page 33: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming
Page 34: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

10. Create an application for a Pizza Delivery Company. You might check out the graphical user interface shown in Figure 10-21. Your solution does not need to resemble this one; however, it might give you some ideas. You must provide a place for the user to enter their contact information (i.e., address, phone number, and e-mail) and some of the contact information should be displayed when an order is placed. Your application should have a picture logo and company name. Provide selections such as Small,Medium, and Large for size. Allow users to select from at least a dozen items to place on their pizza. You might consider offering different types of sauce (i.e., tomato, pesto, or no sauce), different types of crust, different specialty types of pizza (Supreme, Veggie, etc.). BE CREATIVE! You can also sell wings, bread sticks, chicken strips, or something else of your choosing. Consider offering beverages. You must display the price for the order and allow the user to change their mind while they are ordering and reset the order form. Experiment, explore, change properties, and then review the .Designer.cs file.

Page 35: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter11. Advanced OO programming features

PROGRAMMING EXERCISES 1. Create a base class to hold information about sporting teams on campus. It should not be possible to instantiate the class. Include common characteristics such as primary coach and type of sport. Define properties, ToString( ) methods, and a minimum of one virtual method. The ToString( ) method should return the name of the sport and coach.

2. Select two types of sporting teams and define subclasses for them. These classes should inherit from a base team class such as that created in Exercise 1. Include unique characteristics about the sport. For example, for a sporting team such as a tennis team, the field location and/or the person to contact to restring rackets may be of interest. Be sure to implement any virtual methods included in the base class. Provide ToString( ) methods in both subclasses that invokes the ToString( ) method in the base class and adds unique characteristics about the individual team to the return value. 3. Add a new project to the solution you designed for Exercises 1 and 2. The new project should test your designs of the base team class and individual sporting team subclasses. Your class can be a console or Windows application. One approach would be to instantiate objects of both teams when the program launches and then invoke methods and properties to retrieve and display data about both teams. Be sure to retrieve data from the base class as well as the subclasses. 4. Define an interface for the sporting team relating to budgeting. Any teams that implement the interface must provide details about how they are budgeted. Modify your design for Exercises 1 through 3 to implement the interface for both teams. 5. Create a ticket reservation class for issuing tickets to on-campus events such as plays, musicals, and home basketball games. Design the ticket class to be abstract. Create subclasses for at least three different types of events. Determine unique characteristics for each of the events. Define a client application to test your class designs. 6. Create a base class to store characteristics about a loan. Include customer details in the Loan base class such as name, loan number, and amount of loan. Define subclasses of auto loan and home loan. Include unique characteristics in the derived classes. For example you might include details about the specific auto in the auto loan class and details about the home in the home loan class. Create a presentation class to test your design by displaying information about both types of loans. 7. Create a base class for a banking account. Decide what characteristics are common for checking and saving accounts and include these characteristics in

Page 36: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

the base class. Define subclasses for checking and savings. In your design, do not allow the banking base account to be instantiated—only the checking and saving subclasses. Include a presentation class to test your design.

8. Create a base class titled ReadingMaterial. Include subclasses of Book and Magazine. Define an interface called IPrintable that has a method describing how it is available as a hard copy form of publication. Design your classes so that common characteristics are placed in the ReadingMaterial class. Include a presentation class to test your design. 9. Define an application to include classes for Student, GraduateStudent, and UndergraduateStudent. Create .DLL files for the three classes. Include characteristics in the Student class that are common to GraduateStudent and UndergraduateStudent students. All three classes should override the ToString( ) method. GraduateStudent should include a data field for the type of undergraduate degree awarded, such as B.A. or B.S., and the location of the institution that awarded the degree. UndergraduateStudent should include classification (for example, freshman, sophomore), and parent or guardian name and address. Create a presentation class that instantiates student objects and enables details to be displayed on the form about individual students to test your design. 10. Create a housing application for a property manager. Include a base class named Housing. Include data characteristics such as address and year built. Include a virtual method that returns the total projected rental amount. Define an interface named IUnits that has a method that returns the number of units. The MultiUnit class should implement this interface. Create subclasses of MultiUnit and SingleFamily. SingleFamily should include characteristics such as size in square feet and availability of garage. MultiUnit might include characteristics such as the number of units. Create .DLL components for the housing classes. Define a presentation class to test your design.

Page 37: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter13. Working with files

PROGRAMMING EXERCISES 1. Write a C# program that prints the current directory and the name and size of all files that are stored in the directory. Your display should be aesthetically pleasing (numbers should be aligned and formatted). 2. Use Notepad to place 20 integer values in a text file. Write a C# program to retrieve the values from the text file. Display the number of values processed and the average of the values, formatted with two decimal places. Also display the smallest value and the largest value. Hint: To simplify the problem, the values can each be placed on separate lines. 3. Write a program that enables the user to input name, address and local phone number, including area code. The phone number should be entered in a format to include dashes between the numbers (i.e. xxx-xxx-xxxx). Store the values in a text file. Surround the phone number with asterisks and store only the numbers for the phone number. Do not store the hypen or dash in the file with the phone number. Include appropriate exception-handling techniques in your solution. Display a message indicating the data was stored properly. Use Notepad to view the contents. 4. Write a program that displays a graphical user interface (Windows form) that allows multiple names, e-mail addresses, and local phone numbers to be entered. Store the values in a text file. Retrieve and store just the numbers for the phone number. Use separate lines for each person’s data. Include appropriate exception-handling techniques in your solution. 5. Write a program that stores 50 random numbers in a file. The random numbers should be positive with the largest value being 1000. Store five numbers per line and 10 different lines. Use the Random class to generate the values. Include appropriate exception-handling techniques in your solution. 6. Write a program that retrieves the values stored in a text file. The file should contain 10 different rows of data with five values per line. Display the largest and smallest value from each line. Include appropriate exception-handling techniques in your solution. Hint: If you completed Programming Exercise #5, use the text file created by that exercise. 7. Write an application that retrieves a student name and three scores per line from a text file. Process the values by calculating the average of the scores per student. Write the name and average to a different text file. Display what is being written to the new file. Test your application with a minimum of eight records in the original file. Hint: You might consider adding delimiters between the data values in the original text file to simplify retrieving and processing the data.

Page 38: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming
Page 39: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

8. Write a program that produces a report showing the number of students who can still enroll in given classes. Test your solution by retrieving the data from a text file that you create using a text editor, such as Notepad. Some sample data follows. Include the name of the class, current enrollment, and maximum enrollment.

Classes should not be oversubscribed. Define a custom exception class for this problem so that an exception is thrown if the current enrollment exceeds the maximum enrollment by more than three students. When this unexpected condition occurs, halt the program and display a message indicating which course is overenrolled. 9. Write a graphical user application that accepts employee data to include employee name, number, pay rate, and number of hours worked. Pay is to be computed as follows: Hours over 40 receive time-and-a-half pay. Store the employee name, number, and the total amount of pay (prior to deductions) in a text file. Close the file and then, in the same application, retrieve the stored values and display the employee name and the formatted total pay. Your application should allow the user to browse to the file location for saving and retrieving the file. 10. Allow the user to enter multiple sets of five numbers. Store the numbers in a binary file. For each set of values, store the average of the numbers prior to storing the next set of values. For example, if the user entered 27 78 120 111 67 as the first set of values, the first values written to the binary file would be 27 78 120 111 67 80.6. For an extra challenge, close the file, reopen it, and display the values from the file in a listbox control.

Page 40: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter14. Working with databases

PROGRAMMING EXERCISES 1. Create a small Family database with one table to include data about members of your family. Include data fields such as family member number, first name, last name, type of relationship, hometown, and age. You can be creative with the family member number or use the autogenerated number from the database. It must be a unique value; each member of your family must have a different family member number. Populate the database with members of your family. Be sure to include data about yourself in the table. Place at least 10 records in your database table, even if it is necessary to make up information. The type of database (SQL Server or Access) will be determined by your instructor. Write a C# program to display all of the data that appears in the database table on a data grid. 2. Using the database created in Programming Exercise 1, modify your solution to only display the names of the members of your family in a data grid. Dock the grid so that it fills the form. Change the color of the data grid columns, increase the size of the font, choose appropriate headings for your columns, and format the grid control so that it is professionally aesthetically appealing. 3. Using the database created in Programming Exercise 1, write a C# program to only display the names of the members of your family who are over 21 years of age. Display their name, age, and relationship to you. Provide an appropriate heading for the displayed items on the form and format the grid control.

4. Using the database created in Programming Exercise 1, write a C# program to display the names and type of relationship of the members of your family who live in the same hometown as you do. Do not include yourself in the query result. It may be necessary for you to go back into your database and modify some of the records for testing purposes. Display your results in textboxes as opposed to a data grid. Provide appropriate headings and labels. 5. Create a small BankAccount database with one Account table. The Account table should have fields for account number, customer last and first names, and current balance. The type of database (SQL Server or Access) will be determined by your instructor. Populate the table with 8-10 records. Design a user interface that will enable you to display all customers. 6. Create a small Sports database with two tables: Team and Athlete. The Team table should include fields for the type of team (e.g., basketball), coach’s name (both last and first), and the season the sport is most active (S for spring, F for Fall, or B for both). The Athlete table should include fields for student number, student first and last names, and type of sport. Use the same identifier for type of sport in both tables to enable the tables to be related and linked. Populate the tables with sporting teams from your school.

Page 41: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

The type of database (SQL Server or Access) will be determined by your instructor. Write a C# program that displays information about each team, including the names of the athletes.

Page 42: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

7. Create a Books database to include two tables: BookTable and CourseBookTable. The BookTable table should have fields for ISBN number, title, copyright date, primary author, publisher, and number of pages. The CourseBookTable table should have fields for course number and ISBN. Populate the tables with books in your current collection, including the books you are using for your classes. Books that are not associated with a specific course can be placed in the table with a FUN course number. The type of database (SQL Server or Access) will be determined by your instructor.Write a C# program to display the course number (or FUN) and the ISBN and name of the book on the same screen. 8. Create a small database to include customer data. Include the customer numbers, customer names, and customer directional location. Place at least eight records in the database. For the customer directional location field, use the designations of N for North, S for South, and so on. The type of database (SQL Server or Access) will be determined by your instructor. Write a C# program to only display the names of all customers. Do not use the database configuration wizard for this application; write program statements.

9. Using the database created in Programming Exercise 8, write a C# program to display the customer number and name in a data grid. Format the grid control so that it is professionally aesthetically appealing. Allow the user to add records to the database. If your designed solution involves the use of a disconnected database, post the changes back to the live database. Be sure to check the database records to make sure the changes have been made. For an added challenge, write program statements, as opposed to using the database configuration tools wizard. 10. Using the database created in Programming Exercise 8, write a C# program that retrieves records from the customer table and displays them in a grid control. Allow the user to select an entry from the data grid and display the values selected in text boxes with appropriate labels. Display the corresponding customer area for the one selected as full text (i.e., display West instead of the W, which appears in the database). For an added challenge, write program statements, as opposed to using the database configuration tools wizard.

Page 43: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

Chapter15. Web-based applications

PROGRAMMING EXERCISES 1. Create a Web application that enables users to select from a Calendar control object the date of their next exam. Using program statements, retrieve their selection and then display the date along with an appropriate message. If they select a date in the past, display a message and allow them to re-enter a new date. Change background and foreground colors for the Web page. 2. The computer club is selling T-shirts. Create a Web site that allows users to enter their first and last names, phone number and e-mail address. Allow users to select sizes (S, M, L, XL, and XXL) and quantity. Add statements that process the order by calculating the total cost. All shirts except the XXL are $26; the XXL shirt is $30. Retrieve and display the name of the customer placing the order. Display the total cost of their selection including 7% sales tax. 3. Using Web Forms controls, create a Web application to store a user’s To Do List. Include two TextBox objects, a Button object, and a ListBox object. Allow the user to input their name in one textbox and To Do tasks into the other TextBox. Use those values to populate the ListBox object. Allow the user to make a selection for which item to tackle next from the list. Display their name and the selection on a Label object and then remove that item from the ListBox. 4. The computer club has decided to take a field trip to the hometown of one of the members during spring vacation. To determine the destination, each member has been charged with creating a Web page to highlight the features of his hometown. Create a Web application using the ASP.NET Web Forms site template that contains details about your hometown. If you would prefer that the members visit another location, you may choose a different locale. Set the properties on the form for the controls so the form is aesthetically pleasing. Be sure to change both background and foreground colors, font size, and type. 5. Create a similar application to what you developed in Exercise 4 using the ASP.NET Empty Web Site Template. Include an HTML server control that causes a message to be displayed (on a Label object) when the user clicks a button. The message should include additional details about the locale. 6. Create a dynamic Web site that functions like a calculator. Add features for addition, subtraction, multiplication, division, modulation, and so on. 7. Create a Web application that enables the user to enter first name, last name, and e-mail address. Accept those values and store them in a text file. Allow the user to input the path where the file should be stored. After retrieving the values from the user, display on the Web page both the full file path (including

Page 44: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

the name of the file) and all values stored in the file. Confirm that the values are written to the file.

Page 45: Chapter1- Introduction to Computing and Programming ...grail.cba.csuohio.edu/~matos/notes/ist-211/Book-4thEd/MATOS-CShar… · Chapter1- Introduction to Computing and Programming

8. Create a Web site that retrieves and displays the current department chairs from a database. The StudentDataBase.accdb Access database used with examples in this book includes a major table that stores the major id, major name, department chair, and the department phone number. Create a Web site that references this table, or a database table that you create with similar fields. Display on the Web site the name of the major and the chair for the department. Enhance the site by changing background and foreground colors of the page and the grid storing the data. 9. Create a smart device currency converter application. Select two markets, such as U.S. dollar and the Euro. Research the current equivalents and use those values for your calculations. Include an image control and a control that enables the user to input a value. Display the formatted value entered along with its converted counterpart and the exchange rate. 10. Create a smart device application that allows users to input their names, year of birth, and student IDs. Create and display a new security hash value. The new value should consist of the first initial of their names followed by the identification number and the last two digits of their birth year. Append onto the end of those values the total number of characters in their names. For example, if the name Sofyia ElKomaria, birth year 1994, and the ID 12467 is entered, the new identification number would be S124679416. Create an attractive screen with an image control in the background.