Programming exercises


Chapter11. Advanced OO programming features



Download 247.83 Kb.
Page3/3
Date08.05.2017
Size247.83 Kb.
#17660
1   2   3

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

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.



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.

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.



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.

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.


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.


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

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

written to the file.

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.

Download 247.83 Kb.

Share with your friends:
1   2   3




The database is protected by copyright ©ininet.org 2024
send message

    Main page