C# and Windows Forms Exercises for Beginners (step by step)
- 23.5 hours on-demand video
- 2 articles
- 98 downloadable resources
- Full lifetime access
- Access on mobile and TV
- Certificate of Completion
Get your team access to 4,000+ top Udemy courses anytime, anywhere.Try Udemy for Business
- Practice and understand loops, arrays, structures, LINQ, Databases, OOP and more
- Code beginner and intermediate projects using C#
- Become an intermediate programmer by understanding the how and why of each line in your program
- Think like a programmer
- Uderstand project requirements and choose the right approach to each solution
- Construct, identify, and use Windows Form Controls effectively
Hello and thank you for checking out my course. My name is Pavol Almasi, and I am the created and instructor for this course.
Let me just give you a quick overview of what this course is all about.
As the title of the course says, it’s all about C#, Windows Forms, and practice exercises. The course goes over every single exercise (yes, all 100 of them) in a popular college C# textbook: Starting Out with Visual C# by Tony Gaddis. This indeed is a complete set of C# exercises. I show you how to put the theory you learned into practice by solving every exercise in a step by step manner, with every step done on the camera. There are no suddenly appearing code snippets, all coding is done in front of you.
We will always start by going over the exercise requirements first, and then jump straight into coding. I explain what I am doing with every line of code, and at the end of each video we will have solved the exercise to the required specifications.
This course is all about practice. There are no lectures, no overview of the programming concepts or syntax. I do my best to explain what I am trying to accomplish and why, and touch on common pitfalls, too. However, this course is not for someone who needs to be taught the programming concepts from scratch. This is a course for people who need to put the concepts and theory they learned into practice. Therefore, the course is best suited for college students taking C# classes, or self-taught people. Basically people who study C# and need to cement the knowledge by practicing; people who struggle with some concepts in practice; people who just want to do as many practice exercises as they can, and would like to have a reference point to compare their solutions to; people who take C# classes and struggle with their homework; and of course, people who use this book for their classes and need a little help or a reference. Also, people who have basic understanding of C# language, but are not familiar with Windows Forms will benefit from taking this course.
I made the first video of every section available for free preview, so please, go ahead and see how the videos are structured.
The exercises do not go much beyond beginner level, but if you can do all the exercises by yourself – and that is ultimately the goal of this course - you can consider yourself an intermediate, or advanced beginner, as you will have a basic, but solid understanding of common C# features and syntax, and computer concepts: everything from loops to collections to OOP to databases.
Now, this being a course that focuses solely on practice exercises, and because each exercise is coded as a stand alone one, you may find some of the concepts bit repetitive, as the same concepts, such as input validation, or string building etc. may be part of multiple exercises. This is done purposefully, to further drive the concepts to your memory and become second nature to your coding skills.
All exercises are coded in such a way, that follows the chapters in the book. In many cases, it can be argued that there are better, more effective ways to code the solution, however I do not introduce any new concepts until they were already introduced in the corresponding chapter of the book. I do the exercises from the point of view of a student taking C# classes that follow the textbook, not from the point of view of an active developer.
Lastly, although I am using exercises from one textbook only, lot of them are common exercises used throughout other textbooks as well. You do not need to own a copy of the book. All files, such as text files, images, databases etc. that are used in the exercises will be part of the source code you can download with each exercise, and the text of the exercise is provided as well, in description for each exercise; as comment section in the source code; and I also read it at the beginning of each video.
So, if you are ready to dive into C#, and Windows Forms, and if you believe, like I do, that there is no better way to learn programming than by actually programming, then enroll now, and let’s get coding!
Look at the following list of Latin words and their meanings.
Latin sinister - dexter - medium
English left - right - center
Create an application that translates the Latin words to English.
The form should have three buttons, one for each Latin word.
When the user clicks a button, the application should display the English translation in a Label control.
Create an application that displays 5 images in PictureBox controls. The application should perform the following actions:
• When the user clicks the 1 image, the application should display the word One in a message box.
• When the user clicks the 2 image, the application should display the word Two in a message box.
• When the user clicks the 3 image, the application should display the word Three in a message box.
• When the user clicks the 4 image, the application should display the word Four in a message box.
• When the user clicks the 5 image, the application should display the word Five in a message box.
Create an application with five PictureBox controls. Each PictureBox should display a different card from the set of images. When the user clicks any of the PictureBox controls, the name of the card should be displayed in a Label control.
Think of your favorite joke and identify its setup and punch line. Then, create an application that has a Label and two buttons on a form. One of the buttons should read “Setup” and the other button should read “Punch line.” When the Setup button is clicked, display the joke’s setup in the Label control. When the Punch line button is clicked, display the joke’s punch line in the Label control.
Orion is one of the most famous constellations in the night sky. Create an application that displays the Orion image in a PictureBox control. The application should have a button that, when clicked, displays the names of each of the stars. The application should have another button that, when clicked, hides the star names. The names of the stars are Betelgeuse, Meissa, Alnitak, Alnilam, Mintaka, Saiph, and Rigel.
Create an application that lets the user enter the following pieces of data:
• The user’s first name
• The user’s middle name
• The user’s last name
• The user’s preferred title(Mr., Mrs., Ms., Dr., etc.)
Assume the user has entered the following data:
- First name: Kelly
- Middle name: Jane
- Last name: Smith
- Title: Ms.
The application should have buttons that display the user’s name formatted in the following ways:
Ms.Kelly Jane Smith
Kelly Jane Smith
Smith, Kelly Jane, Ms.
Smith, Kelly Jane
Create an application that lets the user enter the food charge for a meal at a restaurant. When a button is clicked, the application should calculate and display the amount of a 15 percent tip, 7 percent sales tax, and the total of all three amounts.
Assuming there are no accidents or delays, the distance that a car travels down an interstate highway can be calculated with the following formula:
Distance = Speed × Time
Create an application that allows the user to enter a car’s speed in miles per hour. The application should have buttons that display the following:
- The distance the car will travel in 5 hours
- The distance the car will travel in 8 hours
- The distance the car will travel in 12 hours
Create an application that allows the user to enter the amount of a purchase.The program should then calculate the state and county sales tax. Assume the state sales tax is 4 percent and the county sales tax is 2 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the
Assuming that C is a Celsius temperature, the following formula converts the temperature to Fahrenheit:
F = (9/5) * C + 32
Assuming that F is a Fahrenheit temperature, the following formula converts the temperature to Celsius:
C = (5/9) * (F - 32)
Create an application that allows the user to enter a temperature.The application should have Button controls described as follows:
• A button that reads Convert to Fahrenheit.If the user clicks this button, the application should treat the temperature that is entered as a Celsius temperature and convert it to Fahrenheit.
• A button that reads Convert to Celsius.If the user clicks this button, the application should treat the temperature that is entered as a Fahrenheit temperature, and convert it to Celsius.
Create an application that lets the user enter his or her weight (in pounds) and height (in inches). The application should display the user’s body mass index (BMI). The BMI is often used to determine whether a person is overweight or underweight for his or her height. A person’s BMI is calculated with the following formula:
BMI = weight × 703 ÷ height (to power of 2)
Create an application with a form similar to this one.When the application runs, the user clicks the buttons to build a sentence, which is shown in a Label control.You can use the same buttons as shown in the figure or make up your own.The Reset button should clear the sentence so the user can start over.
Many financial experts advise that property owners should insure their homes or buildings for at least 80 percent of the amount it would cost to replace the structure. Create an application that lets the user enter the replacement cost of a building and then displays the minimum amount of insurance he or she should buy for the property.
A bag of cookies holds 40 cookies.The calorie information on the bag claims that there are 10 servings in the bag and that a serving equals 300 calories. Create an application that lets the user enter the number of cookies he or she actually ate and then reports the number of total calories consumed.
Create an application with the PictureBox controls display the images of four fruits(a banana, an apple, an orange, and a pear) and each fruit’s calories. When the application starts, the total calories displayed should be zero.Each time the user clicks one of the PictureBoxes, the calories for that fruit should be added to the total calories, and the total calories should be displayed. When the user clicks the Reset button, the total calories should be reset to zero.
Create an application that lets the user enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance. The program should then display the total monthly cost of these expenses and the total annual cost of these expenses.
A painting company has determined that for every 115 square feet of wall space, 1 gallon of paint and 8 hours of labor will be required. The company charges $20.00 per hour for labor. Create an application that allows the user to enter the square feet of wall space to be painted and the price of the paint per gallon. The program should display the following data:
• The number of gallons of paint required
• The hours of labor required
• The cost of the paint
• The labor charges
• The total cost of the paint job
If you own real estate in a particular county, the property tax that you owe each year is calculated as 64 cents per $100 of the property’s value. For example, if the property’s value is $10,000, then the property tax is calculated as follows:
Tax = $10,000 ÷ 100 × 0.64
Create an application that allows the user to enter a property’s value and displays the sales tax on that property.
There are three seating categories at an athletic stadium.For a baseball game, Class A seats cost $15 each, Class B seats cost $12 each, and Class C seats cost $9 each.Create an application that allows the user to enter the number of tickets sold for each class. The application should be able to display the amount of income generated from each class of ticket sales and the total revenue generated.
Converter Create an application that allows the user to enter an integer between 1 and 10 into a TextBox control.The program should display the Roman numeral version of that number. If the number is outside the range of 1 through 10, the program should display an error message.
Scientists measure an object’s mass in kilograms and its weight in Newtons. If you know the amount of mass of an object, you can calculate its weight, in Newtons, with the following formula:
Weight = Mass × 9.8
Create an application that lets the user enter an object’s mass and then calculates its weight. If the object weighs more than 1000 Newtons, display a message indicating that it is too heavy. If the object weighs less than 10 Newtons, display a message indicating that it is too light.
The date June 10, 1960, is special because when it is written in the following format, the month times the day equals the year: 6/10/60
Create an application that lets the user enter a month (in numeric form), a day, and a two-digit year. The program should then determine whether the month times the day equals the year. If so, it should display a message saying the date is magic. Otherwise, it should display a message saying the date is not magic.
The colors red, blue, and yellow are known as the primary colors because they cannot be made by mixing other colors. When you mix two primary colors, you get a secondary color, as shown here:
• When you mix red and blue, you get purple.
• When you mix red and yellow, you get orange.
• When you mix blue and yellow, you get green.
Create an application that lets the user select two primary colors from two different sets of Radio buttons. The form should also have a Mix button. When the user clicks the Mix button, the form’s background should change to the color that you get when you mix the two selected primary colors.
Note: If the user picks the same color from both sets of Radio buttons, set the form’s background to that color.
In the English measurement system, 1 yard equals 3 feet and 1 foot equals 12 inches.Use this information to create an application that lets the user convert distances to and from inches, feet, and yards. The user enters the distance to be converted into a TextBox.A ListBox allows the user to select the units being converted from, and another ListBox allows the user to select the units being converted to.
Note: Be sure to handle the situation where the user picks the same units from both list boxes.The converted value will be the same as the value entered.
Serendipity Booksellers has a book club that awards points to its customers based on the number of books purchased each month. The points are awarded as follows:
• If a customer purchases 0 books, he or she earns 0 points.
• If a customer purchases 1 book, he or she earns 5 points.
• If a customer purchases 2 books, he or she earns 15 points.
• If a customer purchases 3 books, he or she earns 30 points.
• If a customer purchases 4 or more books, he or she earns 60 points.
Create an application that lets the user enter the number of books that he or she has purchased this month and displays the number of points awarded.
A software company sells a package that retails for $99. Quantity discounts are given according to the following table:
100 or more 50%
Create an application that lets the user enter the number of packages purchased.The program should then display the amount of the discount(if any) and the total amount of the purchase after the discount.
A person’s BMI is calculated with the following formula:
BMI = Weight × 703 ÷ Height(power of 2)
In the formula, weight is measured in pounds and height is measured in inches. Enhance the program so it displays a message indicating whether the person has optimal weight, is underweight, or is overweight.A person’s weight is considered to be optimal if his or her BMI is between 18.5 and 25. If the BMI is less than 18.5, the person is considered to be underweight. If the BMI value is greater than 25, the person is considered to be overweight.
Create a change-counting game that gets the user to enter the number of coins required to make exactly one dollar.The program should let the user enter the number of pennies, nickels, dimes, and quarters. If the total value of the coins entered is equal to one dollar, the program should congratulate the user for winning the game.Otherwise, the program should display a message indicating whether the amount entered was more than or less than one dollar.
One gram of fat has 9 calories. If you know the number of fat grams in a particular food, you can use the following formula to calculate the number of calories that come from fat in that food:
Calories from fat = Fat grams × 9
If you know the food’s total calories, you can use the following formula to calculate the percentage of calories from fat:
Percentage of calories from fat = Calories from fat ÷ Total calories
Create an application that allows the user to enter:
• The total number of calories for a food item
• The number of fat grams in that food item
The application should calculate and display:
• The number of calories from fat
• The percentage of calories that come from fat
Also, the application’s form should have a CheckBox that the user can check if he or she wants to know whether the food is considered low fat. (If the calories from fat are less than 30% of the total calories of the food, the food is considered low fat.)
Note: Make sure the number of calories and fat grams are not less than 0. Also, the number of calories from fat cannot be greater than the total number of calories. If that happens, display an error message indicating that either the calories or fat grams were incorrectly entered.
Create an application that lets the user enter a number of seconds and works as follows:
- There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds.
- There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to 3,600, the program should display the number of hours in that many seconds.
- There are 86,400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86,400, the program should display the number of days in that many seconds.
The following table shows a training company’s workshops, the number of days of each, and their registration fees.
Workshop Number of Days Registration Fee
Handling Stress 3 $1,000
Time Management 3 $800
Supervision Skills 3 $1,500
Negotiation 5 $1,300
How to Interview 1 $500
The training company conducts its workshops in the six locations shown in the following table. The table also shows the lodging fees per day at each location.
Location Lodging Fees per Day
When a customer registers for a workshop, he or she must pay the registration fee plus the lodging fees for the selected location.
For example, here are the charges to attend the Supervision Skills workshop in Orlando:
Lodging: $300 × 3 days = $900
Create an application that lets the user select a workshop from one ListBox and a location from another ListBox.When the user clicks a button, the application should calculate and display the registration cost, the lodging cost, and the total cost.
If you know a vehicle’s speed and the amount of time it has traveled, you can calculate the distance it has traveled as follows:
Distance = Speed × Time
For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120 miles. The user enters a vehicle’s speed and the number of hours traveled into text boxes. When the user clicks the Calculate button, the application should use a loop to display in a list box the distance the vehicle has traveled for each hour of that time period.
Modify the Distance Calculator program that you wrote for Programming Problem 1 so it writes its output to a file instead of displaying it in a ListBox control. Open the file in Notepad or Visual Studio to confirm the output.
Assuming that C is a Celsius temperature, the following formula converts the temperature to a Fahrenheit temperature(F):
F = 9/5 * C + 32
Create an application that displays a table of the Celsius temperatures 0–20 and their Fahrenheit equivalents.The application should use a loop to display the temperatures in a list box.
Create an application that predicts the approximate size of a population of organisms.The application should use text boxes to allow the user to enter the starting number of organisms, the average daily population increase (as a percentage), and the number of days the organisms will be left to multiply.For example, assume the user enters the following values:
Starting number of organisms: 2
Average daily increase: 30%
Number of days to multiply: 10
The application should display the table of data in a ListBox control.
Susan is hired for a job, and her employer agrees to pay her every day.Her employer also agrees that Susan’s salary is 1 penny the first day, 2 pennies the second day, 4 pennies the third day, continuing to double each day.Create an application that allows the user to enter the number of days that Susan will work and calculates the total amount of pay she will receive over that period of time.
At one college the tuition for a full-time student is $6000 per semester.It has been announced that the tuition will increase by 2 percent each year for the next five years. Create an application with a loop that displays the projected semester tuition amount for the next 5 years in a ListBox control.
Create an application that generates two random integers, each in the range of 100 through 500. The numbers should be displayed as addition problems on the application’s form, such as 247 + 129 =? The form should have a text box for the user to enter the problem’s answer.When a button is clicked, the application should do the following:
• Check the user’s input and display a message indicating whether it is the correct answer.
• Generate two new random numbers and display them in a new problem on the form.
Create an application that generates a random number in the range of 1 through 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” If the user guesses the number, the application should congratulate the user and then generate a new random number so the game can start over.Optional Enhancement: Enhance the game so it keeps count of the number of guesses that the user makes. When the user correctly guesses the random number, the program should display the number of guesses.
In mathematics, the notation n! represents the factorial of the nonnegative integer n.The factorial of n is the product of all the nonnegative integers from 1 through n. For example,
7! = 1 × 2 × 3 × 4 × 5 × 6 × 7 = 5,040
4! = 1 × 2 × 3 × 4 = 24
Create an application that lets the user enter a nonnegative integer and then uses a loop to calculate the factorial of that number. Display the factorial in a label or a message box.
Create an application that writes a series of random numbers to a file. Each random number should be in the range of 1 through 100. The application should let the user specify how many random numbers the file will hold and should use a SaveFileDialog control to let the user specify the file’s name and location.
This exercise assumes you have completed Random Number File Writer app. Create another application that uses an OpenFileDialog control to let the user select the file that was created by the previous application. This application should read the numbers from the file, display the numbers in a ListBox control, and then display the following data:
• The sum of the numbers
• The number of random numbers read from the file
Create an application that lets the user enter an item’s wholesale cost and its markup percentage. It should then display the item’s retail price. For example:
• If an item’s wholesale cost is $5.00 and its markup percentage is 100 percent, then the item’s retail price is $10.00.
• If an item’s wholesale cost is $5.00 and its markup percentage is 50 percent, then the item’s retail price is $7.50.
The program should have a method named CalculateRetail that receives the wholesale cost and the markup percentage as arguments and returns the retail price of the item.
When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period:
d = 1/2 gt(pow of 2)
The variables in the formula are as follows:
d is the distance in meters,
g is 9.8,
and t is the amount of time in seconds that the object has been falling.
Create an application that allows the user to enter the amount of time that an object has fallen and then displays the distance that the object fell. The application should have a function named FallingDistance. The FallingDistance function should accept an object’s falling time (in seconds) as an argument.The function should return the distance in meters that the object has fallen during that time interval.
In physics, an object that is in motion is said to have kinetic energy.The following formula can be used to determine a moving object’s kinetic energy:
KE = 1/2 mv(pow of 2)
In the formula KE is the kinetic energy, m is the object’s mass in kilograms, and v is the object’s velocity in meters per second.Create an application that allows the user to enter an object’s mass and velocity and then displays the object’s kinetic energy. The application should have a function named KineticEnergy that accepts an object’s mass(in kilograms) and velocity(in meters per second) as arguments.The function should return the amount of kinetic energy that the object has.
A nutritionist who works for a fitness club helps members by evaluating their diets.As part of her evaluation, she asks members for the number of fat grams and carbohydrate grams that they consume in a day.Then, she calculates the number of calories that result from the fat using the following formula:
Calories from fat = Fat grams × 9
Next, she calculates the number of calories that result from the carbohydrates using the following formula:
Calories from carbs = Carbs grams × 4
Create an application that will make these calculations.In the application, you should have the following methods:
• FatCalories–This method should accept a number of fat grams as an argument and return the number of calories from that amount of fat.
• CarbCalories–This method should accept a number of carbohydrate grams as an argument and return the number of calories from that amount of carbohydrates.
Joe’s Automotive performs the following routine maintenance services:
• Oil change—$26.00
• Lube job—$18.00
• Radiator flush—$30.00
• Transmission flush—$80.00
• Muffler replacement—$100.00
• Tire rotation—$20.00
Joe also performs other nonroutine services and charges for parts and labor($20 per hour). Create an application that displays the total for a customer’s visit to Joe’s.
The application should have the following value-returning methods:
• OilLubeCharges—Returns the total charges for an oil change and/or a lube job, if any.
• FlushCharges—Returns the total charges for a radiator flush and/or a transmission flush, if any.
• MiscCharges—Returns the total charges for an inspection, muffler replacement, and/or a tire rotation, if any.
• OtherCharges—Returns the total charges for other services(parts and labor), if any.
• TaxCharges—Returns the amount of sales tax, if any.Sales tax is 6% and is charged only on parts.If the customer purchases services only, no sales tax is charged.
• TotalCharges—Returns the total charges.
The application should have the following void methods, called when the user clicks the Clear button:
• ClearOilLube—Clears the check boxes for oil change and lube job.
• ClearFlushes—Clears the check boxes for radiator flush and transmission flush.
• ClearMisc—Clears the check boxes for inspection, muffler replacement, and tire rotation.
• ClearOther—Clears the text boxes for parts and labor.
• ClearFees—Clears the text boxes in the section marked Summary.
Create an application that calculates the total cost of a hospital stay.The daily base charge is $350. The hospital also charges for medication, surgical fees, lab fees, and physical rehab.The application should accept the following input:
• The number of days spent in the hospital
• The amount of medication charges
• The amount of surgical charges
• The amount of lab fees
• The amount of physical rehabilitation charges
Create and use the following value-returning methods in the application:
• CalcStayCharges—Calculates and returns the base charges for the hospital stay.This is computed as $350 times the number of days in the hospital.
• CalcMiscCharges—Calculates and returns the total of the medication, surgical, lab, and physical rehabilitation charges.
• CalcTotalCharges—Calculates and returns the total charges.
Suppose you want to deposit a certain amount of money into a savings account and then leave it alone to draw interest for the next 10 years.At the end of 10 years you would like to have $10,000 in the account.How much do you need to deposit today to make that happen? You can use the following formula, which is known as the present-value formula, to find out:
P = F / (1 + r)(pow of n)
The terms in the formula are as follows:
• P is the present value, or the amount that you need to deposit today.
• F is the future value that you want in the account. (In this case, F is $10,000.)
• r is the annual interest rate.
• n is the number of years that you plan to let the money sit in the account.
Write a method named PresentValue that performs this calculation.The method should accept the future value, annual interest rate, and number of years as arguments.It should return the present value, which is the amount that you need to deposit today. Demonstrate the method in an application that lets the user experiment with different values for the formula’s terms.
A prime number is a number that can be evenly divided by only itself and 1. For example, the number 5 is prime because it can be evenly divided by only 1 and 5. The number 6, however, is not prime because it can be evenly divided by 1, 2, 3, and 6. Write a Boolean function named IsPrime that takes an integer as an argument and returns true if the argument is a prime number or false otherwise.Use the function in an application that lets the user enter a number and then displays a message indicating whether the number is prime.
TIP: Recall that the % operator divides one number by another and returns the remainder of the division. In an expression such as num1 % num2, the % operator returns 0 if num1 is evenly divisible by num2.
Create an application that lets the user play the game of Rock, Paper, Scissors against the computer.The program should work as follows.
1. When the program begins, a random number in the range of 1 through 3 is generated.If the number is 1, then the computer has chosen rock.If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Do not display the computer’s choice yet.)
2. The user selects his or her choice of rock, paper, or scissors.To get this input you can use Button controls, or clickable PictureBox controls displaying some of the artwork that you will find in the student sample files.
3. The computer’s choice is displayed.
4. A winner is selected according to the following rules:
• If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.)
• If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.)
• If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.)
• If both players make the same choice, the game must be played again to determine the winner.
Be sure to modularize the program into methods that perform each major task.
Create an application that reads a text file’s contents into an array, displays the array’s contents in a ListBox control, and calculates and displays the total of the array’s values.
ChargeAccounts.txt contains a list of a company’s valid charge account numbers.There are a total of 18 charge account numbers in the file, and each one is a 7-digit number, such as 5658845. Create an application that reads the contents of the file into an array or a List. The application should then let the user enter a charge account number. The program should determine whether the number is valid by searching for it in the array or List that contains the valid charge account numbers.If the number is in the array or List, the program should display a message indicating the number is valid.If the number is not in the array or List, the program should display a message indicating the number is invalid.
The local driver’s license office has asked you to create an application that grades the written portion of the driver’s license exam.The exam has 20 multiple-choice questions.Here are the correct answers:
1. B 2. D 3. A 4. A 5. C 6. A 7. B 8. A 9. C 10. D 11. B 12. C 13. D 14. A 15. D 16. C 17. C 18. B 19. D 20. A
Your program should store these correct answers in an array. The program should read the student’s answers for each of the 20 questions from a text file and store the answers in another array. (Create your own text file to test the application.) After the student’s answers have been read from the file, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions.
• Teams.txt—This file contains a list of several Major League baseball teams in alphabetical order.Each team listed in the file has won the World Series at least once.
• WorldSeriesWinners.txt—This file contains a chronological list of the World Series’ winning teams from 1903 through 2012. (The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2012. Note that the World Series was not played in 1904 or 1994.)
Create an application that displays the contents of the Teams.txt file in a ListBox control.When the user selects a team in the ListBox, the application should display the number of times that team has won the World Series in the time period from 1903 through 2012.
TIP: Read the contents of the WorldSeriesWinners.txt file into a List or an array. When the user selects a team, an algorithm should step through the list or array counting the number of times the selected team appears.
• GirlNames.txt—This file contains a list of the 200 most popular names given to girls born in the United States from 2000 through 2009.
• BoyNames.txt—This file contains a list of the 200 most popular names given to boys born in the United States from 2000 through 2009.
Create an application that reads the contents of the two files into two separate arrays or Lists. The user should be able to enter a boy’s name, a girl’s name, or both, and the application should display messages indicating whether the names were among the most popular.
USPopulation.txt contains the midyear population of the United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth.Create an application that reads the file’s contents into an array or a List.The application should display the following data:
• The average annual change in population during the time period
• The year with the greatest increase in population during the time period
• The year with the least increase in population during the time period
Create an application that simulates a game of tic-tac-toe.The form uses eight large Label controls to display the Xs and Os.The application should use a two-dimensional int array to simulate the game board in memory.When the user clicks the New Game button, the application should step through the array, storing a random number in the range of 0 through 1 in each element. The number 0 represents the letter O, and the number 1 represents the letter X. The form should then be updated to display the game board.The application should display a message indicating whether player X won, player Y won, or the game was a tie.
Dr.Hunter teaches three sections of her Intro to Computer Science class. She has 12 students in section 1, 8 students in section 2, and 10 students in section 3. In the Chap07 folder of the Student Sample Programs, you will find the following files:
• Section1.txt—This file contains the final exam scores for each student in section 1. (There are 12 integer scores in the file.)
• Section2.txt—This file contains the final exam scores for each student in section 2. (There are 8 integer scores in the file.)
• Section3.txt—This file contains the final exam scores for each student in section 3. (There are 10 integer scores in the file.)
Create an application that reads these three files and stores their contents in a jagged array.The array’s first row should hold the exam scores for the students in section 1, the second row should hold the exam scores for the students in section 2, and the third row should hold the exam scores for the students in section 3. The application should display each section’s exam scores in a separate ListBox control and then use the jagged array to determine the following:
• The average exam score for each individual section
• The average exam score for all the students in the three sections
• The highest exam score among all three sections and the section number in which that score was found
• The lowest exam score among all three sections and the section number in which that score was found
Create an application with a method that accepts a string as an argument and returns the number of words it contains.
For instance, if the argument is "Four score and seven years ago," the method should return the number 6. The application should let the user enter a string, and then it should pass the string to the method. The number of words in the string should be displayed.
Create an application with a method that accepts a string as an argument and returns a copy of the string with the first character of each sentence capitalized.For instance, if the argument is "hello. my name is Joe. what is your name?" the method should return the string "Hello. My name is Joe. What is your name?" The application should let the user enter a string and then pass it to the method.The modified string should be displayed.
Create an application with a method that accepts a string as an argument and returns the number of vowels that the string contains.The application should have another method that accepts a string as an argument and returns the number of consonants that the string contains. The application should let the user enter a string, and should display the number of vowels and the number of consonants it contains.
Create an application that accepts as input a sentence in which all the words are run together but the first character of each word is uppercase.Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter.For example the string "StopAndSmellTheRoses." would be converted to "Stop and smell the roses."
Create an application that accepts a sentence as input and converts each word to “Pig Latin.” In one version, to convert a word to Pig Latin you remove the first letter and place that letter at the end of the word. Then you append the string "ay" to the word.Here is an example: English: I SLEPT MOST OF THE NIGHT Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY
Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember.On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion:
A, B, and C = 2
D, E, and F = 3
G, H, and I = 4
J, K, and L = 5
M, N, and O = 6
P, Q, R, and S = 7
T, U, and V = 8
W, X, Y, and Z = 9
Create an application that lets the user enter a 10-character telephone number in the format XXX-XXX-XXXX.The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent.For example, if the user enters 555-GET-FOOD, the application should display 555-438-3663.
Create an application that simulates a soft-drink vending machine.The application should let the user select one of the following soft drinks:
• Cola($1.00 each)
• Root Beer($1.00 each)
• Lemon Lime Soda($1.00 each)
• Grape Soda($1.50 each)
• Cream Soda($1.50 each)
When the application starts, the vending machine will have 20 of each type of soft drink. Each time the user selects a drink, the application should subtract 1 from the quantity of the selected drink. It should also update and display the total amount of sales. If the user selects a drink that is sold out, a message should be displayed indicating so. In the application’s code, create a structure that has fields for the following data:
Number of drinks in machine
The program should create an array of five structure objects. Each element of the array should keep data for a specific type of soft drink.
A slot machine is a gambling device into which the user inserts money and then pulls a lever(or presses a button). The slot machine then displays a set of random images.If two or more of the images match, the user wins an amount of money that the slot machine dispenses back to the user.
Create an application that simulates a slot machine. The application should let the user enter into a TextBox the amount of money he or she is inserting into the machine. When the user clicks the Spin button, the application should display three randomly selected symbols. (Slot machines traditionally display fruit symbols. If none of the randomly displayed images match, the program should inform the user that he or she has won $0. If two of the images match, the program should inform the user that he or she has won two times the amount entered.If three of the images match, the program should inform the user that he or she has won three times the amount entered.When the user clicks the Exit button to exit the application, the program should display the total amount of money entered into the slot machine and the total amount won.
Create a class named Pet which has the following properties:
• Name—The Name property holds the name of a pet.
• Type—The Type property holds the type of animal that a pet is. Example values are “Dog”, “Cat”, and “Bird”.
• Age—The Age property holds the pet’s age.
Demonstrate the class in an application that creates an object of the class and lets the user enter the name, type, and age of his or her pet. This data should be stored in the object. Retrieve the pet’s Name, Type, and Age properties and display their values on the screen.
Create a class named Car that has the following properties:
• Year—The Year property holds the car’s year model.
• Make—The Make property holds the make of the car.
• Speed—The Speed property holds the car’s current speed.
In addition, the class should have the following constructor and other methods.
• Constructor—The constructor should accept the car’s year and model and make them as arguments.These values should be assigned to the backing fields for the object’s Year and Make properties.The constructor should also assign 0 to the backing field for the Speed property.
• Accelerate—The Accelerate method should add 5 to the Speed property’s backing field each time it is called.
• Brake—The Brake method should subtract 5 from the Speed property’s backing field each time it is called.
Demonstrate the class in an application that creates a Car object. The application’s form should have an Accelerate button that calls the Accelerate method and then displays the car’s current speed each time it is clicked.The application’s form should also have a Brake button that calls the Brake method and then displays the car’s current speed each time it is clicked.
Create a class that holds the following personal data in properties: name, address, age, and phone number.Demonstrate the class in an application that creates three instances of the class. One instance should hold your information, and the other two should hold your friends’ or family members’ information.Display each object’s properties on the application’s form.
Write a class named Employee that has the following properties:
• Name—The Name property holds the employee’s name.
• IdNumber—The IdNumber property holds the employee’s ID number.
• Department—The Department property holds the name of the department in which the employee works.
• Position—The Position property holds the employee’s job title.
The class should have the following overloaded constructors:
• A constructor that accepts the following values as arguments and assigns them to the appropriate properties: employee’s name, employee’s ID number, department, and position
• A constructor that accepts the following values as arguments and assigns them to the appropriate properties: employee’s name and ID number.The Department and Position properties should be assigned an empty string ("")
• A parameterless constructor that assigns empty strings("") to the Name, Department, and Position properties, and 0 to the IdNumber property
In an application, create three Employee objects to hold the following data:
Name ID Number Department Position
Susan Meyers 47899 Accounting Vice President
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Engineer
The application should store this data in the three objects and display the data for each employee on the screen.
Write a class named RetailItem that holds data about an item in a retail store.The class should have the following properties:
• Description—The Description property should hold a brief description of the item.
• UnitsOnHand—The UnitsOnHand property should hold the number of units currently in inventory.
• Price—The Price property should hold the item’s retail price.
Write a constructor that accepts arguments for each property.The application should create an array of three RetailItem objects containing the following data:
Description Units on Hand Price
Item 1 Jacket 12 59.95
Item 2 Jeans 40 34.95
Item 3 Shirt 20 24.95
The application should have a loop that steps through the array, displaying each element’s properties.
A university has the following dormitories:
Allen Hall $1,500 per semester
Pike Hall $1,600 per semester
Farthing Hall $1,800 per semester
University Suites $2,500 per semester
The university also offers the following meal plans:
7 meals per week $600 per semester
14 meals per week $1,200 per semester
Unlimited meals $1,700 per semester
Create an application with two forms.The main form should allow the user to select a dormitory and a meal plan. The application should show the total charges on the second form.
Create an application with a class named PersonEntry.The PersonEntry class should have properties for a person’s name, e-mail address, and phone number.Also, create a text file that contains the names, e-mail addresses, and phone numbers for at least five people. When the application starts, it should read the data from the file and create a PersonEntry object for each person’s data. The PersonEntry objects should be added to a List, and each person’s name should be displayed in a list box on the application’s main form.When the user selects a name from the list box, a second form should appear displaying that person’s name, e-mail address, and phone number.
Create an Employee class that has properties for the following data:
• Employee name
• Employee number
Next, create a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have properties to hold the following data:
• Shift number(an integer, such as 1, 2, or 3)
• Hourly pay rate
The workday is divided into two shifts: day and night. The Shift property will hold an integer value representing the shift that the employee works.The day shift is shift 1 and the night shift is shift 2. Create an application that creates an object of the ProductionWorker class and lets the user enter data for each of the object’s properties.Retrieve the object’s properties and display their values.
In a particular factory, a shift supervisor is a salaried employee who supervises a shift. In addition to a salary, the shift supervisor earns a yearly bonus when his or her shift meets production goals. Create a ShiftSupervisor class that is derived from the Employee class you created in previous programming exercise. The ShiftSupervisor class should have a property that holds the annual salary and a property that holds the annual production bonus that a shift supervisor has earned. Demonstrate the class in an application.
In a particular factory, a team leader is an hourly paid productionworker that leads a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a minimum number of hours of training per year. Design a TeamLeader class that is derived from the ProductionWorker class you created in previous Programming Problem. The TeamLeader class should have properties for the monthly bonus amount, the required number of training hours, and the number of training hours that the team leader has attended. Demonstrate the class in an application.
Design a class named Person with properties for holding a person’s name, address, and telephone number. Next, design a class named Customer, which is derived from the Person class. The Customer class should have a property for a customer number and a Boolean property indicating whether the customer wishes to be on a mailing list. Demonstrate an object of the Customer class in a simple application.
A retail store has a preferred customer plan where customers can earn discounts on all their purchases. The amount of a customer’s discount is determined by the amount of the customer’s cumulative purchases in the store as follows:
• When a preferred customer spends $500, he or she gets a 5 percent discount on all future purchases.
• When a preferred customer spends $1,000, he or she gets a 6 percent discount on all future purchases.
• When a preferred customer spends $1,500, he or she gets a 7 percent discount on all future purchases.
• When a preferred customer spends $2,000 or more, he or she gets a 10 percent discount on all future purchases.
Design a class named PreferredCustomer, which is derived from the Customer class you created in Programming Problem 4. The PreferredCustomer class should have properties for the amount of the customer’s purchases and the customer’s discount level. Demonstrate the class in a simple application.
- Students should have installed Visual Studio in order to follow along.
- Students should be actively learning C# and Windows Forms
- Students should be familiar with the programming concepts presented in the exercises
Visual C# is an excellent programming language. It’s the main language in the .Net family of languages, and as such, it allows you to program some truly amazing solutions. So, congratulations on choosing to learn this amazing language. :-)
As it is common among beginner programmers, the enthusiasm to learn often is not enough to make the leap from beginner to intermediate.
The bad news is: code fear is real, and it hinders, or even stops your progress. The good news is: you can learn to eliminate it! And all it takes is a little practice and determination. And that’s where this course will help you greatly!
The course goes over C# programming projects from a popular college C# textbook: "Starting Out with Visual C#" by Tony Gaddis. I show you how to put the theory you learned into practice by showing you how to solve each exercise and walking you through all the Why’s and How’s.
Because the course goes over ALL exercises from one text book, some of the concepts are repeated across multiple exercises. The course is not meant to follow any particular guidline where each exercise builds up on the previous one, but rather serves as a comprehensive reference, allowing students to skip exercises that present concepts the student is already familiar with.
You and I will go on a journey to program simple solutions using basic programming techniques, all the way to more complex Database and OOP solutions.
In the process, you will learn the ins and outs of C# language. You will learn how to translate the project requirements into a working code. You will learn to use many different programming concepts, such as Conditional Statements, Loops, Arrays, Multi-dimensional arrays, LINQ, OOP, databases… and pick the right one for your solution. But above all, you will learn to think like a programmer!
This course is all about practice. Therefore, to benefit from this course, you need to be an active student. It doesn't matter if you are self-taught or attend a programming course. What matters is the time and effort you are willing to put into learning and practicing your skills.
There are no lectures in this course. However, I do my best to explain what I am trying to accomplish with each line of code, and touch on common pitfalls, too.
This is a course for beginner C# .net programmers who need to put the concepts and theory they learned into practice and for people who prefer to learn by doing.
If that's you, then let's start coding!
- The course is best suited for students taking C# classes, or self-taught students.
- Beginners who are currently learning how to program in C# and need a guided practice exercises.
- Students who need to put the concepts and theory they learned into practice.
- Beginner C# .Net programmers seeking to cement the knowledge by doing short programming projects that are challenging, yet not out of his/her skill set exercises.
- Students who take C# classes and struggle with their homework, or students who need a little help or a reference will love this course.