grail.cba.csuohio.edugrail.cba.csuohio.edu/.../matos-csharp-doyle4th-progra…  · web view4....

73
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(); } } }

Upload: vonhan

Post on 07-Feb-2018

235 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter1- Introduction to Computing and Programming

PROGRAMMING EXERCISES

1. Write a program that produces the following output. Replace the nameTyler 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 ofthe programming language discussed in this text. You should be morecreative, but one possible design is given here.

Page 2: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

3. Print your name, school, and the year you plan to graduate. Place your nameon one line and your graduation year on the second line. Be sure to includeappropriate labels. For example, my information would look like the following,if I planned to graduate in 2017:Name: Barbara DoyleGraduation Year: 2017School: Jacksonville University

4. Develop an application that produces a banner containing information aboutyour project. Items you might include are your programming assignmentnumber, name, date submitted and the purpose of the application. Label eachitem. These are items you might want to include as internal documentationon future programming assignments. Your output for your banner mightlook 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, besure 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. Onepossible design follows.*******——————————————————————————————————*******——————————————————————————————————*******——————————————————————————————————*******———————————————————————————————————————————————————————————————————————————

Page 3: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

—————————————————————————————————————————

Page 4: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

6. Create an application that produces three different outputs using the samephrase. Select your own favorite popular saying for the phrase. The phraseshould first be displayed on one line. Use at least three Write( ) methods - butthe output should all appear on a single line.

Then print the phrase on three lines, again using only Write( ) methods. Foryour third and final output, print your favorite saying one word per line.Decide which combination of Write( ) and/or WriteLine( ) would be themost streamlined approach. Following is an example of what the final outputwould 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 eachpiece of information, place each of the items on separate lines and place abackslash (\) after each entry. Begin and end the entire listing with the |character. Include the full listing in a box of asterisks. Your output might looksimilar to the following:

Page 5: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator
Page 6: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

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

9. Create an application that displays the following patterns. You may use anycharacter of your choice to construct the pattern. One possible solutionfollows.

10. Write your initials in block characters to a standard output device. Designyour prototype using the symbol(s) of your choice. For example, my initialsin block characters are shown below.

BBBBBBBBBBBBBB AA DDDDDDDDDDDDDDDDDBB BB AA AA DD DDBB BBBB AA AA DD DDBB BB AA AA DD DDBB BB AA AA DD DDBBBBBB AA AA AA AA AA AA DD DDBB BB AA AA DD DDBB BB AA AA DD DDBB BBBB AA AA DD DDBB BB AA AA DD DDBBBBBBBBBBBBBBB AA AA DDDDDDDDDDDDDDDDD

Page 7: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter2. Data Types and Expressions

PROGRAMMING EXERCISESFor 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 kilometermeasurement.

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 appropriately2labeled retail and wholesale values for the shoes.

Page 8: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

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 commissionedsales employee. Perform a compile-time initialization and store the name ofNesbith Lang in a variable called employeeName. Nesbith earns 7% of her totalsales as her commission. Her federal tax rate is 18%. She contributes 10% to aretirement program and 6% to Social Security. Her sales this month were$161,432. Produce a formatted report showing the amount for each of thecomputed items. Select appropriate constants. After you finish displaying NesbithLang’s data, change the values and rerun the application.

6. Write a program that computes the average of five exam scores. Declare andperform a compile-time initialization with the five values. Use a constant todefine the number of scores. Print all scores and the average value formattedwith no digits to the right of the decimal. Rerun the application with differentvalues.

7. Write a program that prints the number of quarters, dimes, nickels, andpennies that a customer should get back as change. Run your program onceby performing a compile-time initialization using 92 cents for the value tobe converted. Go into your source code and change the 92 to 27. Rerun theapplication.

8. Write a program that computes a weighted average giving the following weights.Homework: 10%Projects: 35%Quizzes: 10%Exams: 30%Final Exam: 15%

Page 9: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Do a compile-time initialization with the following values:Homework: 97; Projects: 82; Quizzes: 60; Exams: 75; Final Exam 80. Displayall values, including the weights, appropriately labeled and formatted. Rerunthe application with different values.

9. Write a program that computes the amount of money the computer club willreceive from the proceeds of their granola project. Each case has 100 bars. Thegranola bars sell for $1.50 per bar. Each case costs $100.00. They are required togive the student government association 10% of their earnings. Display theirproceeds, showing the amount given to the student government association.Show all the values formatted with currency. Do a compile-time initializationusing 29 for cases sold.

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

Page 10: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter3. Methods and Behavior

PROGRAMMING EXERCISES

1. Write an application that includes two additional methods in addition to theMain( ) method. One method should return a string consisting of four orfive lines of information about your school. The other method should returna string consisting of asterisks. First call the method that returns the string ofasterisks. Call the method that returns the asterisk a second time after youinvoke the method that displays the information about your school. Itemsyou might include are the name of your school, number of students enrolled,and school colors. Include appropriate labels. The display should be aestheticallypleasing so include enough asterisks to surround your listing.

2. Design a message display application. Allow users to enter their name andfavorite saying in a single method that gets invoked two times. First call themethod asking for the person’s name. Send a string argument indicating whatvalue should be entered. Invoke the method a second time to retrieve thefavorite saying. Return the string values back to the Main( ) method. Callanother method, sending the name and saying. From that method, display themessage showing the person’s name and their saying surrounded by rows ofgreater than/less than symbols(<><><>).

3. Write an application that allows a user to input the height and width of arectangle and output the area and perimeter. Use methods for entering thevalues, performing the computations, and displaying the results. Resultsshould be formatted and printed in a tabular display.

4. Design an application using methods that convert an integer number ofseconds to an equivalent number of hours, minutes, and seconds. Use

Page 11: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

methods for entering the initial seconds, performing the computations, anddisplaying the results. Results should be formatted and printed in a tabulardisplay.

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 theoriginal temperature and the formatted converted value. Use appropriatemethods for entering, calculating, and outputting results.

6. Write a program that can be used to convert meters to feet and inches. Allowthe user to enter a metric meter value in a method. Write appropriatemethods for your solution.

7. Write a program that can be used to determine the tip amount that shouldbe added to a restaurant charge. Allow the user to input the total, beforetaxes and the tip percentage (15% or 20%). Produce output showing thecalculated values including the total amount due for both the 15% and the20% 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 clubwill receive from proceeds of their granola bar sales project. Allow the userto enter the number of cases sold and the sale price per bar. Each casecontains 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 theirearnings. Display their proceeds formatted with currency. Write appropriatemethods for your solution.

9. Write a program that calculates and prints the take-home pay for a commissionedsales employee. Allow the user to enter values for the name of theemployee and the sales amount for the week. Employees receive 7% of thetotal sales. Federal tax rate is 18%. Retirement contribution is 15%. Social

Page 12: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Security tax rate is 9%. Use appropriate constants. Write input, display, andcalculation 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 propertytax will be for the current year. Taxes are based on the property’s assessedvalue and the annual mileage rate. The established mileage rate for thecurrent year is $10.03 per $1000 value. Homeowners are given a $25,000tax exemption, which means they may subtract $25,000 from the assessedvalue prior to calculating the taxable value. Enable users to enter theproperty address and the prior year’s assessed value. The township hasdecided to increase all properties’ assessed value 2.7% for the current yearto add additional monies to the school budget line. Provide methods tocompute and return the new assessed value and the proposed taxes for thecurrent year. Provide another method that displays the formatted values.

Page 13: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter4. Creating your own classes

PROGRAMMING EXERCISES1. Create a class representing a student. Include characteristics such as studentnumber, first and last name, overall GPA, classification, and major.

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 withdirections. 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 fullname of the motorway, full name of the motorway and whether it is toll ornot, and full name of the motorway and the number of lanes. Also include aToString( ) method that returns all data members with appropriate labels.Include enough constructors to make the class flexible and experiment withusing the class diagram to create the property members.

3. Create an Employee class. Items to include as data members areemployee number, name, date of hire, job description, department, andmonthly 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 simplicityyou may assume each receipt contains a single item number. Includeappropriate constructors and properties plus an additional method thatcalculates the total cost using the quantity and unit price. Override theToString ( ) method to return the information about the customer (name

Page 14: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

and phone number) and the total cost of the item purchased. Create asecond 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 amethod that returns the month name (as a string) as part of the date. Separatethe day from the year with a comma in that method. Include appropriateconstructors, properties, and methods. Override the ToString ( ) methodto display the date formatted with slashes (/) separating the month, day, andyear.

6. Create a Trip class. Include as data members destination, distance traveled,total cost of gasoline, and number of gallons consumed. Includeappropriate constructors and properties. Add additional methods that calculatesmiles 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. IncludeIncrementMoney and DecrementMoney instance methods. Include constructorsthat enable the Money class to be instantiated with a single valuerepresenting the full dollar/cent amount as well as a constructor that enablesyou to create an instance of the class by sending two separate integervalues representing the dollar and cent amounts. Include an instance methodthat returns as a string the number of dollars, quarters, nickels, dimes, andpennies 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 aPark class. Include data members such as name of park, location, type of(i.e., national, state, local) facility, fee, number of employees, number ofvisitors recorded for the past 12 months, and annual budget. Write separateinstance methods that a) return a string representing name of the park, the

Page 15: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

location and type of park; b) return a string representing the name of thepark, the location and facilities available; c) compute cost per visitor basedon annual budget and the number of visitors during the last 12 months; andd) compute revenue from fees for the past year based on number of visitorsand fee. Also include a ToString( ) method that returns all data memberswith appropriate labels. Create a second class to test your Park class.

9. Write a program that includes an Employee class that can be used tocalculate and print the take-home pay for a commissioned sales employee.All employees receive 7% of the total sales. Federal tax rate is 18%. Retirementcontribution is 10%. Social Security tax rate is 6%. Write instancemethods to calculate the commission income, federal and social security taxwithholding amounts and the amount withheld for retirement. Use appropriateconstants, design an object-oriented solution, and write constructors.Include at least one mutator and one accessor method; provide properties forthe 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 salesamount for the week in the second class.

10. Write a program that creates a ProfessorRating class consisting ofprofessor ID and three ratings. The three ratings are used to evaluateeasiness, helpfulness, and clarity. In a separate implementation class, allowthe user to enter the values. Call the constructor to create an instance of theProfessorRating class. Include appropriate properties. Do not allowthe ID to be changed after an object has been constructed. Provide amethod in the ProfessorRating class to compute and return theoverall rating average. Print all ratings and the average rating formatted withno digits to the right of the decimal from the implementation class. Use asingle class method to enter all data.

Page 16: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter5. Making Decisions

PROGRAMMING EXERCISES1. Write an application that will enable you to display an aquarium’s pH level. ThepH is a measure of the aquarium water’s alkalinity and is typically given on a 0-14scale. For most freshwater fish tanks, 7 is neutral. Tanks with a pH lower than 7are considered acidic. Tanks with a pH higher than 7 are alkaline. Allow the userto 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. Includea member method that returns the name of the month and another method thatreturns the number of days in the month. The ToString( ) method shouldreturn the name and number of days. Write a second class to test your Monthclass. The second class should allow the user to input a month number. Displaythe name of the month associated with the number entered and the number ofdays in that month. For this exercise, use 28 for February. If the user inputs aninvalid 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 theBMI is calculated, display a message of the person’s status. Prompt the user forboth their weight and height. The BMI status categories, as recognized by theU.S. Department of Health & Human Services, are shown in the table below:BMI Weight StatusBelow 18.5 Underweight

Page 17: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

18.5 - 24.9 Normal25 - 29.9 Overweight30 & above Obese

4. Write a program that calculates the take-home pay for an employee. The twotypes of employees are salaried and hourly. Allow the user to input the employeefirst and last name, id, and type. If an employee is salaried, allow the user to inputthe salary amount. If an employee is hourly, allow the user to input the hourly rateand the number of hours clocked for the week. For hourly employees, overtime ispaid for hours over 40 at a rate of 1.5 of the base rate. For all employees’ takehomepay, federal tax of 18% is deducted. A retirement contribution of 10% and aSocial 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 18: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

5. A large Internet merchandise provider determines its shipping charges based onthe number of items purchased. As the number increases, the shipping chargesproportionally decrease. This is done to encourage more purchases. If a singleitem is purchased the shipping charge is $2.99. When customers purchasebetween 2 and 5 items, they are charged the initial $2.99 for the first item andthen $1.99 per item for the remaining items. For customers who purchase morethan 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 firstitem, $1.99 per item for items 2 through 5, and $1.49 per item for items 6through 14 and then just $0.99 per item for the remaining items. Allow the userto 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 figurethey want to see calculated. Based on the value inputted, prompt for appropriatedimensions and perform the calculations using the following formulas:

Area of a circle = pi * radius2

Area of a rectangle = length * widthSurface area of a cylinder = 2 * pi * radius * height + 2 * pi * radius2

Write a modularized solution, which includes class methods for inputting dataand performing calculations.

Create an application with four classes. Three of the classes should contain dataand behavior characteristics for circle, rectangle, and cylinder. The fourth classshould allow the user to input a figure type from a menu of options. Prompt for

Page 19: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

appropriate values based on the inputted figure type, instantiate an object of thetype entered, and display characteristics about the object.

8. Design a solution that prints the amount of profit an organization receives basedon it sales. The more sales documented, the larger the profit ratio. Allow the userto input the total sales figure for the organization. Compute the profit based onthe following table. Display the sales and profit formatted with commas, decimals,and a dollar symbol. Display the profit ratio formatted with a percentsymbol.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 andtested. Use the decimal data type for your solution. What values did you enter andtest 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 theAmerican side, it is sold by the gallon. Write an application that allows the userto input information from both stations and make a decision as to which stationoffers the most economical fuel price. Test your application with 1.259 per literagainst 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 itsequivalent roman numeral value. Display an error message if the value entered isoutside of the acceptable range. Write a two class solution. The second classshould allow the user to input a test value.

Page 20: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter6. Repeating Instructions

PROGRAMMING EXERCISES1. 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 largestof 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 valuesboth less than and greater than the acceptable range as well as non-numericdata. When the user is finished inputting data, display the number of valid andinvalid entries entered.

3. Write a program to calculate the average of all scores entered between 0 and100. Use a sentinel-controlled loop variable to terminate the loop. Aftervalues are entered and the average calculated, test the average to determinewhether an A, B, C, D, or F should be recorded. The scoring rubric is asfollows: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 andshipping. Allow the user to input any number of item prices. Sales tax of7.75% is charged against the total purchases. Shipping charges can be determinedbased on the number of items purchased. Use the following chart to determinethe shipping charge. Display an itemized summary containing the total purchasecharge, number of items purchased, sales tax amount, shipping charge, and grandtotal.fewer than 3 items $3.503 to 6 items $5.007 to 10 items $7.0011 to 15 items $9.00more than 15 items $10.00

Page 21: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

5. Write a program that allows the user to input any number of hexadecimalcharacters. Sum the values and display the sum as a hexadecimal value. Withinthe loop, convert each character entered to its decimal equivalent. Treat eachsingle inputted character as a separate value. Display the original hex value andthe corresponding decimal value. For example, if the user inputs F, 15 would bedisplayed 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 hexidecimaland decimal notation.

6. Write an application that will enable a vendor to see what earnings he can expectto make based on what percentage he marks up an item. Allow the user to inputthe wholesale item price. In a tabular form, show the retail price of the itemmarked up at 5%, 6%, 7%, 8%, 9% and 10%.

Page 22: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

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 themultiplication table. Display a column in the table beginning with the firstbase 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 (beginningbase value + 1), through 1 times the ending base value. The last row shouldbe 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 through8. Display an error message if an invalid base is entered. Display an aestheticallyformatted multiplication table. An example of output produced when 2and 8 are entered appears in Figure 6-22.

8. Prompt the user for the length of three line segments as integers. If the three linescould form a triangle, print the integers and a message indicating they form atriangle. Use a state-controlled loop to allow users to enter as many differentcombinations as they want.

9. Write an application that calculates a student’s GPA on a 4.0 scale. Grade point

Page 23: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

average (GPA) is calculated by dividing the total amount of grade points earnedby the total amount of credit hours attempted. For each hour, an A receives 4grade points, a B receives 3 grade points, a C receives 2 grade points, and a Dreceives 1 grade point.Allow the user to input any number of courses and associated grades. Displaythe number of hours earned and the GPA.

Page 24: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter7. Arrays

PROGRAMMING EXERCISES1. Write a program that reads data into an array of type int. Valid values are from 0to 10. Your program should display how many valid values were inputted as wellas the number of invalid entries. Output a list of distinct valid entries and a countof 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 overthe past few months. Write a program that accepts any number of monthly salesamounts. Display the total of the values. Display a report showing each originalvalue entered and the percentage that value contributes to the total. You mayprompt the user for the number of values to be inputted.

3. Write a temperature application. Your solution should be a two class applicationthat has a one-dimensional array as a data member. The array stores temperaturesfor any given week. Provide constructors for instantiating the class and methodsto return the highest temperature, lowest temperature, average temperature, andthe average temperature excluding the lowest temperature. Provide a methodthat accepts as an argument a temperature and returns the number of days thetemperatures were below that value. Override the ToString( ) method toreturn a listing of all the temperatures in three column format and the temperaturerange 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 placedifferent values in two of the arrays. Write a program to store the product of the

Page 25: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

two arrays in the third array. Produce a display using the MessageBox classthat shows the contents of all three arrays using a single line for an element fromall three arrays. For an added challenge, design your solution so that the twooriginal arrays have a different number of elements. Use 1 as the multiplier whenyou produce the third array.

5. Write a program that allows the user to enter any number of names, last namefirst. Using one of the predefined methods of the Array class, order the namesin ascending order. Display the results.

6. Write a two class application that has as a data member an array that can store statearea codes. The class should have a member method that enables users to test anarea 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 Arrayclass 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 eachsurrounded by parentheses. To test the class, store a list of state codes in a onedimensionalarray. Send that array as an argument to the class. Your applicationshould work with both an ordered list of area codes or an unordered list.

Page 26: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

7. Write an application that allows the user to input monthly rainfall amounts forone year. Calculate and display the average rainfall for the year. Display themonth 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 valuefrom 0 through 10. Prompt the user for a new score if they enter a value outsideof the specified range. Prompt the user for a new value if they enter analphabetic character. Store the values in an array. Calculate the average excludingthe lowest and highest scores. Display the average as well as the highest andlowest scores that were discarded.

9. Write a program that allows any number of values between 0 and 10 to beentered. When the user stops entering values, display a frequency distributionbar chart. Use asterisks to show the number of times each value was entered. If agiven number is not entered, no asterisks should appear on that line. Yourapplication should display error messages if a value outside the acceptable rangeis entered or if a non-numeric character is entered.

10. Write a two class solution that includes data members for the name of thecourse, current enrollment, and maximum enrollment. Include an instancemethod that returns the number of students that can still enroll in the course.The ToString( ) method should return the name of the course, currentenrollment, and the number of open slots. Design your solution using parallelarrays. Declare an array of class objects in your implementation class. Test yourapplication with the following data:

Page 27: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator
Page 28: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter8. Advanced Colletions

PROGRAMMING EXERCISES1. Write an application that creates and returns a one-dimensional array containingall the elements in the two-dimensional array. Store the values in a row majorformat. For testing purposes, you may do a compile-time initialization of a 12 x 5two-dimensional array. Display both the two-dimensional and the one-dimensionalarray. 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 areperforming selling five different products. You should use a two-dimensionalarray 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 sothat any number of salesmen and any number of products can be displayed. Whenyou display your final output, print the salesman’s last name only, sales for eachproduct, 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 productwas sold.

4. Write a two class application that creates a customer code to be placed on amailing label for a magazine. Allow the user to input their full name with the firstname 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

Page 29: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

(number) they purchased a subscription and ask for their zip code. Your mailinglabel should contain the last name, followed by their year of birth, the number ofcharacters in the full name, the first three characters of the month they purchasedthe subscription, and the last two digits of their zip. The code for Bob Clocksomborn 01/22/1993, who purchased his subscription during the 10th month of theyear and lists 32226 as his zip code would be Clocksom9312Oct26.

5. Write a program that allows the user to enter any number of names. Yourprompt can inform the user to input their first name followed by a space andlast name. Order the names in ascending order and display the results with the lastname listed first, followed by a comma and then the first name. If a middle initialis entered, it should follow the first name. Your solution should also take intoconsideration that some users may only enter their last name (one name).

6. Write an application that creates a two-dimensional array. Allow the user toinput the size of the array (number of rows and number of columns). Fill thearray with random numbers between the 0 and 100. Search the array for thelargest value. Display the array values, numbers aligned, and the indexes wherethe largest value is stored.

Page 30: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

7. Write a program that creates a two-dimensional array with 10 rows and 2columns. The first column should be filled with 10 random numbers between0 and 100. The second column should contain the squared value of the elementfound 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 whizwith 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 syntaxrules). 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 theword 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 thenew Pig Latin phrase.

9. Write an application that displays revenue generated for exercise classes at the TappanGym. The gym offers two types of exercise classes, zumba and spinning, six days perweek, four times per day. Zumba is offered at 1, 3, 5, and 7 p.m.; spinning is offeredat 2, 4, 6, and 8 p.m. When attendees sign up, they agree to pay $4.00 per class forzumba and $5.00 for spinning. Produce a table displaying the number of attendeesper time slot. Display a row and column of totals showing the total number ofattendees by day and also time period. Also include a column showing the revenuegenerated each day and the overall revenue per type of exercise. Do a compile-timeinitialization of your data structures using data from the following table.

Page 31: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

10. Write an application that enables you to randomly record water depths for5 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, andSavannah. For ease of input, you may want to code the locations (i.e., SurfCity = 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 lastvalue entered into the array. After the data is entered, display the average depthat each location and the average depth by time period.

Page 32: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter 9. Introduction to Windows Programming

PROGRAMMING EXERCISES1. Create a Windows application that can be used to input a user’s name. Include anappropriate label indicator for the name and a textbox for the input entry.A button labeled OK should retrieve and display the value entered on anotherlabel positioned near the bottom of the form. The font color for all objects shouldbe yellow. Change the background color of the form to an appropriate one to usewith 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 RetrievalApp’’ to the form. Initially clear the text from the label that will display your finalanswer. When the OK button is pressed, retrieve the name and concatenate thatvalue with a Congratulatory message. For example, you might display, ‘‘Congratulations,Brenda Lewis, you retrieved the data!’’, if your name was BrendaLewis. Align the controls so they are aesthetically pleasing. Be sure to change thedefault names of all controls involved in program statements.

2. Create a Windows application that can be used to change the form color. Yourform background color should initially be blue. Provide at least two buttons withtwo different color choices. Change the font style and size on the buttons. Alignthe buttons so that they are in the center of the form. The buttons should be thesame size. Add event handlers for the buttons so that when the user clicks thebutton, the form changes color, and a message box is displayed alerting the user asto what color the form is. Be sure to name any controls used in programstatements prior to registering your event. Change the default title bar text.

Page 33: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Hint: This exercise may require you to do some research. You may want to reviewthe 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 onebutton. The textboxes should be used to allow the user to input the x- and ycoordinatesto indicate where the form should be positioned. When the userclicks the button, the window should be moved to that new point. Be sure tolabel the textboxes appropriately. Change the form’s background color. Add atitle 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 thecoordinates.

Hint: One easy way to do this is to set the location using an instance of thePoint class when the user clicks the button. To do this, you could allow theuser to input values for both x and y into two separate textbox objects. Afterbeing retrieved, they would need to be parsed or converted to their integerequivalent. Then use the numeric values for x and y to set the location by typingLocation = new Point(x,y);.

Page 34: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

4. Create a Trip Calculator Windows application that can be used to determinemiles per gallon for a given trip. Set the Form object properties of Name,ForeColor, BackColor, Size, Location, Text, and AcceptButton. Theform should contain labels and textboxes to allow the user to input trip destination,miles traveled, and gallons of gas consumed. Two buttons should be placedon the form. Name all objects used in program statements. When the user clicksthe button that performs the calculations, display in a label the miles per gallonfor 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. Thetextboxes should be used to allow the user to input two positive numeric values.The buttons should be labeled Add and Multiply. Create event-handler methodsthat retrieve the values, perform the calculations, and display the result of thecalculations on a label. The result label should initially be set to be invisible with afont color of yellow. If invalid data is entered, change the font color to red on theresult label and display a message saying ‘‘Value must be numeric and > 0.’’

When the final answer is displayed, the font color should be yellow. Additionallabels will be needed for the textboxes captions. Do not allow non-numericcharacters to be entered. Invoke the TryParse( ) method to retrieve thevalues. All controls involved in program statements should be named. Rightjustify values in the textbox.

6. Create a Windows application that contains a textbox for a person’s name. Planthat 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

Page 35: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

should be included. When the button is clicked, retrieve the full name, separate itinto first, middle (if present), and last names and then display the labeled namevalues.

7. Create a Windows application that contains two textboxes and three buttons. Oneof the textboxes and one of the buttons are initially invisible. The first textboxshould be used to input a password. The textbox should be masked to somecharacter of your choosing so that the characters entered by the user are not seenon the screen. When the user clicks the first button, the second textbox and buttonshould 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 thesecond button, have the application compare the values entered to make sure theyare 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 traveledgiven speed and time. Recall that distance = speed * time. Provide textboxes fortime and speed and a button to calculate to the distance. Be sure only numericdata is able to be entered into the textboxes. Experiment with the controls’properties. Spend time with your design so that your GUI is very user friendlyand looks nice.

Page 36: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

9. Create a Windows application that functions like a banking account register.Separate the business logic from the presentation layer. The graphical userinterface should allow the user to input the account name, number, and balance.Provide textbox objects for withdrawals and deposits. A button should beavailable for clicking to process withdrawal and deposit transactions showingthe new balance.

10. Create the higher/lower guessing game using a graphical user interface. Allowusers to keep guessing until they guess the number. Keep a count of the numberof guesses. Choose two colors for your game: one should be used to indicatethat the value the users guessed is higher than the target; the other is used toindicate that the value the users guessed is lower than the target. With each newguess, show the guess count and change the form color based on whether theguess is higher than the target or lower. When they hit the target, display amessage on a label indicating the number of guesses it took. Several approachescan be used to seed the target: one is to generate a random number byconstructing an object of the Random class. For example, the followingstores a random whole number between 0 and 100 in target:

Random r = new Random();int target = r.Next(0,101);

Page 37: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter10. Programming based on events

PROGRAMMING EXERCISES1. Create a graphical user interface that allows the users to enter personalinformation such as their names, e-mail addresses, and phone numbers.Include a menu that provides a minimum of four features. The first displaysthe information entered by the user in a message box. The second clears theentries so that new values can be entered, the third menu option displaysinformation about the application such as who developed it and what versionit is. Another menu option closes the application. Be creative and be sure toproduce an aesthetically pleasing design using options from the Format menuif you are using Visual Studio.

2. Create a Windows application that can be used as a sign-up sheet for skiequipment for the Flyers Sports Club. The club has ski equipment that itmakes available to members at a minimal charge. In an attempt to determinewhat type of equipment members might need for an upcoming trip, theyhave asked you to design and implement an equipment-needs form. IncludeCheckBox objects that allow users to select the type of gear they will needto purchase for the trip. Include selections of snow gloves, skis, goggles,earmuffs, and other items you feel are appropriate. Include at least one pictureimage on your application. After all selections are made, display a messageindicating what items have been selected. You will probably want to includemenu options to display and clear the order for the next user. Also include anoption that enables the user to exit the application.

3. Create a graphical user interface that can be used by a community group toenable youths to sign up for different sporting events. Include radio buttonswith five different sport names. Only one of these should be selectable.Program your event-handler method so that a message is displayed with each

Page 38: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

selection of a different sport. For example, if one of the sports is skiing, themessage might say, ‘‘Bring warm clothes!’’ Also include a PictureBoxobject on the form to display pictures of the sporting event. When theparticular sport is selected, make the PictureBox visible. You can find freegraphics on the Internet to use in your application. Hint: One way toassociate a file to the PictureBox control is to Import an image from theImage property.

4. Create a Message Displayer that has one ComboBox object with a list of atleast four of your favorite sayings. In your design, include the capability ofletting users enter their own sayings. When a selection is made or a new entryis typed, display the selection on a Label object on your form. Add amenu to the application that includes at least the menu options of Format andHelp. Under the Format selection, include options of Font and Color. Wirethe Font and Color options to the Windows predefined Font and Colordialog boxes so that when their values are changed, the text in the Labelobject displaying the saying is changed.

Page 39: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

5. Create an order form that allows bags to be purchased. There are sixdifferent types: full decorative, beaded, pirate design, fringed, leather, andplain. Create a ListBox object for the different styles. Include aComboBox for quantity. Quantities up to 10 should be provided. Afterthe user makes a selection, display a message indicating which selectionwas made. Include an option to clear selections. Provide appropriateerror messages when selections are not made.

6. Add to the application in Exercise 5 by including a control that allows the userto determine the type of shipping they desire. Include a set of radio buttons thatcontain shipping options of overnight, three day, and standard. Add the pricefor 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 onthe total purchase. The following percentages are used: overnight—10%; threeday—7%; and standard—5%. Display in a message box the shipping chargealong with the selection, quantity, and total cost.

7. The computer club is selling T-shirts. Create an attractive user interface thatallows users to select sizes (S, M, L, and XL) and quantity. Which controlswould be most appropriate? Remember, the fewer keystrokes required ofthe user the better. Display the selections made by the user with the Processmenu option. Include an option to exit the application.

8. Add to your solution in Exercise 7 by including two more sizes, XSmall andXXLarge. 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

Page 40: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

an ‘‘Add to Cart’’ option from the Process menu that enables the user to addmultiple selections to the order. Display the total cost for each selection and thefinal cost for the order. Include a Help menu option that displays instructions.

9. Create aWindows application for purchasing floor covering. Allow the lengthand width (feet and inches) of a room to be entered. Be sure to include programstatements that will keep your program from crashing if they enter nonnumericcharacters for the room dimensions. Have a control that displaysdifferent types along with the prices of floor covering. Using the tab control,provide selections such as Hardwood, Carpet, and Laminate. On each tab allowthe 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 persquare yard for Oak and $41.95 per square yard for Cherry. After the users entertheir room dimensions and selects the floor covering and price, display the totalcost to cover the room. Include an option to clear selections. Place both thetype of floor covering and the price in a single control, such as a ComboBoxand use string manipulation techniques to strip the price out of the string.

Page 41: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

10. Create an application for a Pizza Delivery Company. You might check outthe graphical user interface shown in Figure 10-21. Your solution does notneed to resemble this one; however, it might give you some ideas. You mustprovide 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 bedisplayed when an order is placed.Your application should have a picture logo and company name. Provideselections such as Small,Medium, and Large for size. Allow users to select fromat least a dozen items to place on their pizza. You might consider offeringdifferent types of sauce (i.e., tomato, pesto, or no sauce), different types ofcrust, different specialty types of pizza (Supreme, Veggie, etc.). BECREATIVE! You can also sell wings, bread sticks, chicken strips, orsomething else of your choosing. Consider offering beverages.You must display the price for the order and allow the user to change theirmind while they are ordering and reset the order form. Experiment,explore, change properties, and then review the .Designer.cs file.

Page 42: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter11. Advanced OO programming features

PROGRAMMING EXERCISES1. Create a base class to hold information about sporting teams on campus. Itshould not be possible to instantiate the class. Include common characteristicssuch 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. Theseclasses should inherit from a base team class such as that created in Exercise1. Include unique characteristics about the sport. For example, for a sportingteam such as a tennis team, the field location and/or the person to contact torestring rackets may be of interest. Be sure to implement any virtualmethods included in the base class. Provide ToString( ) methods inboth subclasses that invokes the ToString( ) method in the base classand 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. Thenew project should test your designs of the base team class and individualsporting team subclasses. Your class can be a console or Windows application.One approach would be to instantiate objects of both teams when theprogram launches and then invoke methods and properties to retrieve anddisplay data about both teams. Be sure to retrieve data from the base class aswell as the subclasses.

4. Define an interface for the sporting team relating to budgeting. Anyteams that implement the interface must provide details about how they arebudgeted. Modify your design for Exercises 1 through 3 to implement theinterface for both teams.

5. Create a ticket reservation class for issuing tickets to on-campus eventssuch as plays, musicals, and home basketball games. Design the ticket class

Page 43: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

to be abstract. Create subclasses for at least three different types of events.Determine unique characteristics for each of the events. Define a clientapplication to test your class designs.

6. Create a base class to store characteristics about a loan. Include customerdetails in the Loan base class such as name, loan number, and amount of loan.Define subclasses of auto loan and home loan. Include unique characteristicsin the derived classes. For example you might include details about thespecific auto in the auto loan class and details about the home in the homeloan class. Create a presentation class to test your design by displayinginformation about both types of loans.

7. Create a base class for a banking account. Decide what characteristics arecommon for checking and saving accounts and include these characteristics inthe base class. Define subclasses for checking and savings. In your design,do not allow the banking base account to be instantiated—only the checkingand saving subclasses. Include a presentation class to test your design.

8. Create a base class titled ReadingMaterial. Include subclasses of Bookand Magazine. Define an interface called IPrintable that has amethod describing how it is available as a hard copy form of publication.Design your classes so that common characteristics are placed in theReadingMaterial class. Include a presentation class to test yourdesign.

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 GraduateStudentand UndergraduateStudent students. All three classes shouldoverride the ToString( ) method. GraduateStudent should includea 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

Page 44: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

presentation class that instantiates student objects and enables details to bedisplayed on the form about individual students to test your design.

10. Create a housing application for a property manager. Include a base classnamed 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 thenumber of units. The MultiUnit class should implement this interface.Create subclasses of MultiUnit and SingleFamily. SingleFamilyshould include characteristics such as size in square feet and availability ofgarage. MultiUnit might include characteristics such as the number ofunits. Create .DLL components for the housing classes. Define a presentationclass to test your design.

Page 45: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter13. Working with files

PROGRAMMING EXERCISES1. Write a C# program that prints the current directory and the name and sizeof all files that are stored in the directory. Your display should be aestheticallypleasing (numbers should be aligned and formatted).

2. Use Notepad to place 20 integer values in a text file. Write a C# program toretrieve the values from the text file. Display the number of values processedand the average of the values, formatted with two decimal places. Also displaythe smallest value and the largest value. Hint: To simplify the problem, thevalues can each be placed on separate lines.

3. Write a program that enables the user to input name, address and local phonenumber, including area code. The phone number should be entered in aformat to include dashes between the numbers (i.e. xxx-xxx-xxxx). Store thevalues in a text file. Surround the phone number with asterisks and store onlythe numbers for the phone number. Do not store the hypen or dash in the filewith the phone number. Include appropriate exception-handling techniquesin 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) thatallows multiple names, e-mail addresses, and local phone numbers to beentered. Store the values in a text file. Retrieve and store just the numbersfor the phone number. Use separate lines for each person’s data. Includeappropriate exception-handling techniques in your solution.

5. Write a program that stores 50 random numbers in a file. The random numbers

Page 46: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

should be positive with the largest value being 1000. Store five numbers perline 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 shouldcontain 10 different rows of data with five values per line. Display the largestand smallest value from each line. Include appropriate exception-handlingtechniques 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 froma 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 theoriginal file. Hint: You might consider adding delimiters between the datavalues in the original text file to simplify retrieving and processing the data.

Page 47: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

8. Write a program that produces a report showing the number of studentswho can still enroll in given classes. Test your solution by retrieving the datafrom a text file that you create using a text editor, such as Notepad. Somesample data follows. Include the name of the class, current enrollment, andmaximum enrollment.

Classes should not be oversubscribed. Define a custom exception class for thisproblem so that an exception is thrown if the current enrollment exceeds themaximum enrollment by more than three students. When this unexpectedcondition occurs, halt the program and display a message indicating whichcourse is overenrolled.

9. Write a graphical user application that accepts employee data to includeemployee name, number, pay rate, and number of hours worked. Pay is tobe computed as follows: Hours over 40 receive time-and-a-half pay. Storethe 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, retrievethe stored values and display the employee name and the formatted total pay.Your application should allow the user to browse to the file location forsaving and retrieving the file.

10. Allow the user to enter multiple sets of five numbers. Store the numbers in a

Page 48: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

binary file. For each set of values, store the average of the numbers prior tostoring the next set of values. For example, if the user entered 27 78 120111 67 as the first set of values, the first values written to the binary file wouldbe 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 49: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter14. Working with databases

PROGRAMMING EXERCISES1. Create a small Family database with one table to include data about membersof your family. Include data fields such as family member number, first name,last name, type of relationship, hometown, and age. You can be creative withthe family member number or use the autogenerated number from thedatabase. It must be a unique value; each member of your family must havea different family member number. Populate the database with members ofyour family. Be sure to include data about yourself in the table. Place at least10 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 yourinstructor. Write a C# program to display all of the data that appears in thedatabase table on a data grid.

2. Using the database created in Programming Exercise 1, modify your solutionto only display the names of the members of your family in a data grid. Dockthe 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# programto only display the names of the members of your family who are over 21years of age. Display their name, age, and relationship to you. Provide anappropriate heading for the displayed items on the form and format the gridcontrol.

4. Using the database created in Programming Exercise 1, write a C# programto display the names and type of relationship of the members of your familywho live in the same hometown as you do. Do not include yourself in the

Page 50: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

query result. It may be necessary for you to go back into your database andmodify some of the records for testing purposes. Display your results intextboxes as opposed to a data grid. Provide appropriate headings and labels.

5. Create a small BankAccount database with one Account table. The Accounttable should have fields for account number, customer last and first names,and current balance. The type of database (SQL Server or Access) will bedetermined by your instructor. Populate the table with 8-10 records. Designa user interface that will enable you to display all customers.

6. Create a small Sports database with two tables: Team and Athlete. The Teamtable 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 forFall, or B for both). The Athlete table should include fields for studentnumber, student first and last names, and type of sport. Use the sameidentifier for type of sport in both tables to enable the tables to be relatedand linked. Populate the tables with sporting teams from your school.The type of database (SQL Server or Access) will be determined by yourinstructor. Write a C# program that displays information about each team,including the names of the athletes.

Page 51: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

7. Create a Books database to include two tables: BookTable andCourseBookTable. The BookTable table should have fields for ISBN number,title, copyright date, primary author, publisher, and number of pages. TheCourseBookTable table should have fields for course number and ISBN.Populate the tables with books in your current collection, including the booksyou are using for your classes. Books that are not associated with a specificcourse can be placed in the table with a FUN course number. The type ofdatabase (SQL Server or Access) will be determined by your instructor.Write aC# program to display the course number (or FUN) and the ISBN and name ofthe book on the same screen.

8. Create a small database to include customer data. Include the customernumbers, customer names, and customer directional location. Place at leasteight records in the database. For the customer directional location field, usethe 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 databaseconfiguration wizard for this application; write program statements.

9. Using the database created in Programming Exercise 8, write a C# programto display the customer number and name in a data grid. Format the gridcontrol so that it is professionally aesthetically appealing. Allow the user toadd records to the database. If your designed solution involves the use of adisconnected database, post the changes back to the live database. Be sure tocheck the database records to make sure the changes have been made. For anadded challenge, write program statements, as opposed to using the databaseconfiguration tools wizard.

Page 52: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

10. Using the database created in Programming Exercise 8, write a C# programthat retrieves records from the customer table and displays them in a gridcontrol. Allow the user to select an entry from the data grid and display thevalues selected in text boxes with appropriate labels. Display the correspondingcustomer area for the one selected as full text (i.e., display West insteadof the W, which appears in the database). For an added challenge, writeprogram statements, as opposed to using the database configuration toolswizard.

Page 53: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

Chapter15. Web-based applications

PROGRAMMING EXERCISES1. Create a Web application that enables users to select from a Calendar controlobject the date of their next exam. Using program statements, retrieve theirselection and then display the date along with an appropriate message. If theyselect 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 entertheir first and last names, phone number and e-mail address. Allow users to selectsizes (S, M, L, XL, and XXL) and quantity. Add statements that process the orderby 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. Displaythe 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 otherTextBox. Use those values to populate the ListBox object. Allow the user tomake a selection for which item to tackle next from the list. Display their nameand the selection on a Label object and then remove that item from theListBox.

4. The computer club has decided to take a field trip to the hometown of one of themembers during spring vacation. To determine the destination, each member hasbeen 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

Page 54: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

that contains details about your hometown. If you would prefer that the membersvisit another location, you may choose a different locale. Set the propertieson the form for the controls so the form is aesthetically pleasing. Be sure tochange both background and foreground colors, font size, and type.

5. Create a similar application to what you developed in Exercise 4 using theASP.NET Empty Web Site Template. Include an HTML server control thatcauses a message to be displayed (on a Label object) when the user clicks abutton. The message should include additional details about the locale.

6. Create a dynamic Web site that functions like a calculator. Add features foraddition, 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 theuser to input the path where the file should be stored. After retrieving thevalues from the user, display on the Web page both the full file path (includingthe name of the file) and all values stored in the file. Confirm that the values arewritten to the file.

Page 55: grail.cba.csuohio.edugrail.cba.csuohio.edu/.../MATOS-CSharp-Doyle4th-Progra…  · Web view4. Develop an ... print your favorite saying one word per line. ... 4. Create a Trip Calculator

8. Create a Web site that retrieves and displays the current department chairsfrom a database. The StudentDataBase.accdb Access database used with examplesin this book includes a major table that stores the major id, major name,department chair, and the department phone number. Create a Web site thatreferences 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 thepage and the grid storing the data.

9. Create a smart device currency converter application. Select two markets, suchas U.S. dollar and the Euro. Research the current equivalents and use thosevalues for your calculations. Include an image control and a control that enablesthe user to input a value. Display the formatted value entered along with itsconverted counterpart and the exchange rate.

10. Create a smart device application that allows users to input their names, year ofbirth, and student IDs. Create and display a new security hash value. The newvalue should consist of the first initial of their names followed by the identificationnumber and the last two digits of their birth year. Append onto the end ofthose values the total number of characters in their names. For example, if thename Sofyia ElKomaria, birth year 1994, and the ID 12467 is entered, the newidentification number would be S124679416. Create an attractive screen withan image control in the background.