CS30-Project # 5-Chapter 6: Repetition- Total = 50.0 pts Due date: (By 11:30 p.m. (Local Time), Monday, 03/02/ 2020 in Canvas)
This PDF file consists of Thirteen (13) pages
Please read all of the following instructions carefully!
Houseman1
Please note: For full credit, the following two (2) assignments must be completed by the above due date and submitted to
For this project students should implement programming constructs pertaining to Visual Programming Topics covered Chapter Six (6) of the Textbook.
Supplementary Materials:
It is also highly recommended that you review
1. PowerPoint Presentation
2. The PDF file, containing Notes for Chapter Six
3. The compressed folder containing Chapter_6_Solutions to all Programming
Examples and Chapter_6_Solutions to all odd-numbered Programming Exercises.
The above documents, plus this programming project file are uploaded under “Visual Basic Projects” Text Heading. Please check “Week Seven “in Canvas.
**IMPORTANT**: For a quick access to these documents, save them under a suitable folder on your computer.
Late Assignment are not accepted. There is no grace period for any online assignment. All assignments are required to be submitted/uploaded to Canvas LMS, on or before their deadlines. Under no circumstance should any online assignment be submitted to the course instructor’s IVC email account. No Exceptions!
As stated in the course syllabus, effective consistency with fundamental and basic topics covered in this online course must be observed. It is strongly recommended that you adhere to using ONLY programming elements (materials) that are presented (covered) in chapter 6 of our textbook. Please refrain from including materials that may be found on the Internet or other sources. Furthermore, students are required to maintain academic integrity and taking the necessary step to avoid .
.
independently by each online student
Canvas
plagiarism
Failure to do so is subject to substantial penalty
Steps for creating Visual Basic projects:
When you write a Visual Basic application, you should follow number of important steps, for planning the project and then repeat these steps for creating the project. These steps involve setting up the user interface, defining the properties, and then creating the code.
Planning
• Design the user interface: When you plan the user interface, you draw a sketch of the screens you will see when running your project. On your sketch, show the forms and all the controls that you plan to use. Indicate the names that you plan to give the form and each of the objects on the form.
• Plan the properties: For each object (control) that you will place on the form, write down the properties that you plan to set or change during the design of the form.
• Plan the Visual Basic code. In this step, you plan the classes and procedures that will execute when your project runs. You will determine which events require action to be taken and then make a step-by-step plan for those actions. Later, when you actually write the Visual Basic code, you must follow the language syntax rules. But during the planning stage, you will write out the actions using pseudocode, which is an English-Like expression or comment that describes the action. For example, you must plan for the event that occurs when the user clicks on the Exit button. The pseudocode for the event could be Terminate the project or Quit.
Programming
After you have completed the planning steps you are ready to begin the actual construction of the project. Use the same steps that you used for planning.
• Define the user interface: When you define the user interface, you create the forms and controls that you designed in the planning stage. Think of this step as defining the objects you will use in your application.
• Set the properties: When you set the properties of the objects (controls), you give each object (control) a name and define such attributes as the contents of a label, the size of
the text, and the words that appear on top of a button and in the form’s title bar. You
might think of this step as describing each object.
• Write the Visual Basic code: You will use Visual Basic programming statements, using
the Visual Basic syntax to carry out the actions needed by your program. You will be surprised and pleased by how few statements you need to create a powerful Windows program. You can think of this third step as defining the actions of your program.
: A that appears in the Code Editor should describe the . This make the control name very helpful to
anyone reading the application’s programming statements. it is a good programming practice to have the Name property of each control object start with a three-letter prefix that identifies the type of control used in the applications’ Code view.
For instance, for a Form control the prefix is “frm”, for a Button control, the prefix is “btn”, for a Label the prefix is “lbl”, and for a TextBox control the prefix is “txt”, and so forth.
Additionally, it is of vital importance that default Form1.vb name will be renamed in the project’s Solution Explorer, and in the Properties window. Furthermore, the
Houseman2
Naming Rule
control’s name
control’s purpose in the application
property of each control including, the Form should be also appropriately set under the Property window, while in the Designer window for more meaningful visual purpose.
For example, as shown blow, the first programming assignment name is Projectile Motion. While you are designing the Form in the Designer window, under the Solution Explorer of this programing assignment, rename it from Form1.vb to either “frmProjectileMotion.vb”, or simply “frmBall.vb”, as this assignment assumes a ball is thrown. Next, perform the same operation, and change the Form1.vb, in the Property Window.
Best Practices: Please note that descriptive naming convention is of the most important task in programming design. Take the initiative as early as possible when planning and programming all Visual Basic Assignments.
Failure to follow the , for each of the programming assignments in this project will result in a .
Comments: A well prepared Visual Basic program should consist of plain English readable annotations (comments) that will document and describe to the reader of the programmer’s intent.
In-line Comments: are placed within the program source code, summarizing and explaining the intent of single programming code, or block of codes within the program. In Visual Basic, all comments start with a comment delimiter (‘), and they are ignored by compiler.
Introductory Comments: Unlike in-line comments that are placed within the source code, introductory comments are placed at the top of the Visual Basic Code Editor, documenting program’s name, the program developers’ name, date of completion and a brief description as what the program intended to do.
Please note: To enter introductory comments for a particular assignment, while your user interface (Form) is displayed in the Design View, right click with the mouse on the form and select “View Code “and enter your introductory comments before the “Public Class ….” line of code.
Houseman3
‘ Project:
‘ Programmer
‘ Date:
‘ Description:
Name of the project
Your Name
Date completed
Briefly describe what the project is desired to achieve.
Naming Rule
deduction of 10%
Houseman4 Failure to provide for each of the assignments in this
programming project will result in a (10 Percent).
Input Validation: Input Validation, adds more stability to the code and your program in general. It is a good practice to use a process of inspecting the user input values and determine whether they are valid. An error that occurs while an application is running is called exception. If your code does not handle an exception, an error message will be displayed and then the application will abruptly terminate.
While, a Visual Basic application is running, there are numerous types of exceptions that may be thrown. A list of common types of exceptions are displayed in Chapter 8, Table 8.1, page 421, section 8.2 of the text, nonetheless, an exception that most commonly occurs, while the user does not enter valid data, is the infamous InvalidCastException. This exception may be thrown if it is not properly handled. This means that conversion of an instance of one type to another type is not supported.
As you may encounter on Figure 8.9, on page 420, in chapter 8 of the text, when the user is expected to enter an integer value in a text box for input, inadvertently the user may leave the text box entry blank. Then, at runtime, an System.InvalidCastException may be thrown, that indicates “conversion from string “ “ to type ‘integer’ is not valid.
Remember that all types of entry in a text box for input is treated by Visual Basic as string. For instance, if an integer value is expected for entry, such as 49, the above exception may occur, if the user leaves the entry blank or enters “FortyNine”, and non- numeric value. Therefore, it is strongly recommended that while developing your VB applications, you should ensure that user enters valid data.
A proper construct of “Input Validation” when implemented in the code should always ensure that user entry is valid. As a developer, the “Input Validation” that you implement in the code, should be constructed in such a way that checks for all possible user’s entries for errors.
In the “Notes for Chapter Four “, there is a section on exception handling clause “Try- Catch “blocks. This method was briefly discussed and supported with appropriate programming example. We will discuss “Try-Catch “blocks in more details in chapter 8.
Additionally, in chapter 4 of the text, the author present simple programing tools, as discussed On page 118. Here, you encounter such as “IsNumeric(strVar) “method that returns “True”, if the value of “ “can be converted with typecasting functions “CInt “or “CDbl”, otherwise it will return “False “. In
introductory comments
deduction of no more than 10%
Boolean-valued functions,
strVar
case of invalidated input by the user, you may then use a “ “to warn the user with a brief message. Please also check Example 9 “ ” on pp 130- 131 of your text. Remember, you should always prevent data conversion Exceptions.
Failure to comply with the Input Validation will result in a deduction of no more than10% from the total point(s), designated for each of the programming assignment in this project.
1. Run, and save your VB program. To ensure that your entire program works properly, providing you with desired output, run, and check for possible syntax, runtime and logic errors, correct your program, load and run the program until you have the satisfactory results.
2. Program’s files and folders. All VB programs generate numerous files and folders, for example for the Projectile Motion program, you will have generated the following;
Please note: At no time should you move or remove any of above Files or Folders, otherwise your program will not work.
*Important* When you start a new Visual Basic program, using Windows
Forms Application, please enter the name of the programming assignment as you find at the top of the assignment description, such as our first programming assignment “Projectile Motion “.
As you start to develop your programming assignment, use its name in the “Name:” text box at the bottom of your “New Project” dialog box, and browse and save it at a location on your computer that is commonly used for developing and storing your weekly projects. Please refrain from using the default names, such as “WindowsApplication1” or “Assignment1”.
Once, you have completed all the steps for creating your project (i.e. designing, coding, error checking, etc.) Then use “Save All” under the File Menu on the Menu bar and save your project. This process when completed will have a project
folder by the same name as Projectile Motion, which will also contain are VB
generated files and folders.
Message Dialog Box
Houseman5
Input Validation
Extremely Important
: All Visual Basic Programs consists of numerous files and folders.
If in doubt contact the Computer Lab for help.
(Please note: Never use a pound sign (#) for the file or folder name when saving the program. You may encounter technical problem when submitting your VB project via Canvas.) Please further note: At no time should you move or remove any of above files or folders, before they are saved properly in the new folder, otherwise your program will not work when you upload your project to Canvas.
Now perform the above step for the next programming assignment, “Hotel_ Occupancy “in this project, and create separate folders for each of these programming
assignments. Once completed, you should have the same number of new folders as the number of assignments in Project5 folder, as follows;
Projectile Motion
Hotel_ Occupancy
The next step is to get ready to upload your Project5 to Canvas.
3. CompressedfolderforsubmissionofyourprojecttoCanvas;Gatherthetwofolders corresponding to the above programming assignments and place them in yet another folder. This is the final folder, and name it; .
Please note that your full name must be part of the folder, otherwise, it cannot be distinguished from one student to the other.
Now, use the compression utility of Windows operating system and make a compressed folder of this folder “Project 5_You Full Name. Next, be sure “CONTENT” module is in sight, find the entry for the project, upload it, then click on the Submit Assignment button, before the due date/time, to send the document to the instructor, via Canvas,
This compressed folder is the only folder to be submitted to CANVAS for this project
Note:
IVC Computer Lab: During the entire semester computer lab access is available to all enrolled students. Further details are available at: http://academics.ivc.edu/successcenter/Pages/default.aspx. The Student Success Center is located at BSTIC110, First Floor. For more information, please call Irvine Valley Student Success Center (Monday through Thursday: 9 am -7 pm, Friday 9 am -2 pm, Saturday 10 am – 2 pm) (Ph #: 949- 451-5471).
Please Note: The Computer Lab is instructor supported. Please contact Student Success Center at IVC for further direction
Free Tutoring: All enrolled students are required to obtain and complete Tutorial 301 Referral Form. This form can be obtained at: http://academics.ivc.edu/successcenter/Pages/free.aspx. Since this is an online course, and the course instructor is not available at the campus, you are
Houseman6
Project5_You Full Name
Project5
If you use any other compression utility (third party compression utility), such as
WinZip
,
7-Zip
,
WinRaR
, in order to upload your completed project to Canvas, you
will be notified that the instructor of the course cannot open your compressed
folder, in which case your project will not be graded or feedback provided
required to take the form to the Counselling Center in Student Services 210 for authorization from the counselor on duty. Then bring your signed form to the Student Center in BSTIC 110.
Completing Assignments at IVC Computer Lab: For administrative purposes, it is necessary to associate the computer lab with an existing lab course structure. The Computer Lab is instructor supported. Spring semester 2019, please contact professor Youlin Shaw-Kingery
at yshawkinger@ivc.edu.
Professor Shaw-Kingery hours are; Tuesday – Thursday, 12:30 – 7 pm.
**IMPORTSANT**: Please observe the “48 Hours Rule” to contact the course instructor for any inquiry on any of the online assignments in this course to be assisted with help-pointers on the current online assignment you seek assistance for. Please use your campus provided email address, state the course name “CS30” followed by your inquiry you are making in the subject line. At the end of your email message, please enter your full name and student ID #.
Houseman7
Internet Connection & Canvas Compatible Browser
online course, you must have
Assignment # 1: (25 points): (
and posttest forms of the
: At all times, while you are attending this , and Canvas compatible browser.
For this assignment, use pretest constructs.)
Internet availability
Required:
Do loop
Problem Statement (Projectile Motion): Design and develop a Visual Basic application, using a Projectile Motion to provide information on the height of a ball thrown straight up into
the air. As can initial input, the program should request the initial height, h in number of feet, (let us refer to initial height as h0, meaning h with subscript zero) and the initial velocity, v in number of feet per second (let us refer to initial velocity as v0, meaning v with subscript zero).
Let assume this programming assignment is completed. When it is loaded in Visual Studio IDE, the initial screen should resemble, as shown below.
Input Validation: The user should not leave the textboxes for the entry of the Initial Height and Initial Velocity, empty, or enter invalid input. The input in these textboxes must be numeric (preferably of Decimal data type. See pp 60-1 in text). In case of invalid entry by the user you may then use a “Message Dialog Box
How it works!
Required: Use a Sub-procedure “InputData()“ to check for valid entry by the user for the Initial Height and Initial Velocity. This sub-procedure should be placed in your programming
code and be accessible by some procedures in the code, when initial values by the user are requested.
The formula: The height of the ball (in feet) after t seconds is given by the formula:
h + v t − 16t 2 feet. It should be coded as: height = h0 + v0 * t – 16 * t * t
For each of the following four (4) tasks, use an appropriate event handler.
(a) Determine the maximum height of the ball:
(Required: use a Function to compute the maximum height of the ball- The trajectory
(the movement of the ball in the air) will resemble a parabolic curve that opens downward (resembling an inverted U pattern, like “∩ “), with the maximum height at its
vertex. The ball will reach its maximum height after v0/32 seconds.)
]
(b) Determine approximately when the ball will hit the ground:
:
Houseman8
[Also, remember that we cannot measure, the maximum height the ball reaches, in
negative sense.
There are two
possibilities (occasions), when
the height of the ball will be zero (0)
(Note
foot.
i. ii.
First, at time zero (0 second), before the ball is thrown into the air (h0). .
Second, at the time, the ball reaches the ground, after following its parabolic
pattern
Required: Use a Function to compute the height of the ball for every one-tenth (0.1) of a second, while the ball is in the air, until it hits the ground, at height zero (0) foot. This will determine the approximate time (t) in seconds, when the ball hits the ground, by using the formula: height = h0 + v0 * t – 16 * t * t to compute the height of the ball for every one-tenth (0.1) of a second.
Please note: The Visual Basic Compiler internal calculation may not produce the desired precision of accuracy. Try to experience with using increments other than (0.1) seconds, for instance, you may use increments of (0.01) or (0.001) second.
]
(c) Display a table of values:
Required: Use a Sub-procedure to display a table of values showing the height of
the ball for every quarter of second ( 0.25 ), until the time the ball hits the ground. (c))
[Also, remember that we cannot measure, the approximate time the ball hits the
ground, in negative sense.
Required:
Use of a list box to display the table of values for the ball movement under
two column headings “
Time
”, and “
Height
”, for this part
[Also, remember that values are displayed in the table should not possibly measure
the height of ball or the time of its movement, in negative sense.
Required: For effective visual display at the time of the output, please use “Courier New font “, which should correctly align the text in the list box.
The following display depicts the Form and its controls once you load the application
]
Houseman9
(d) Quit. Exit the application.
Once you run the application, you will need to provide, the initial height of the ball in feet h0, and the initial velocity v0, in feet per second
Assume that the of the ball, h0, is zero (0) feet, and the initial velocity of the ball, v0, is . Of course, the program should work for any values.
Based on the required Task (a) stated above the of the ball is displayed (determined based on the initial entries, h0, and (see below!)
initial height
36 feet/second
Maximum Height
v0
Next, based on the required Task (b) stated above the
Ground, is determined based on the initial entries, h0, and (see below!)
Approximate Time until Ball Hits the
v0
Houseman10
Next, based on the required Task (c) stated above a table of values Display Table is displayed a showing the height of the ball every quarter (0.25) second, until it hits the ground, based on the initial entries, h0, and v0 (see below!)
:
]
.)
Finally, perform the required task (d) as stated above, and quit the application.
Recommended naming convention: For control objects appearing in the Code Editor.
[Note
Once the ball hits the ground there should be no further display of the Time and Height. It
does not make sense to measure height / time, in a negative sense
(Remember that we cannot measure, height of an object or even time the movement of an
object, in negative sense
Name Property
Text Property
Control Type
Description
frmBall txtInitialHeight
txtInitialVelocity btnMaxHeight btnApproxTime
btnTable
“Height” lstOutput
Projectile Motion
Determine Maximum Height Determine Approximate
Form
Text Box
Text Box Button Button
Holds application’s controls
Captures user’s input for initial height
Captures user’s input for initial velocity Triggers the event to compute maximum height Triggers the event to compute the approximate
time the ball hits the ground
Triggers the event to display “Time”, and
Triggers the event to exit the program Columnar display of “Time”, and “Height”
btnQuit
Quit
Button
Button List Box
Time until Ball Hits the Ground Display Table
h0
v0
Remember that in addition of the above, you are required to apply suitable naming convention
to all variables that are declared and used (
accessed in the application
) in the program code.
Assignment 2: (25 points): (Required: For this assignment, use a For….Next loop construct. Then within, the , you are advised to use either form of the construct.
Problem Statement: (Hotel Occupancy) The ElGrande Hotel in Acapulco, Mexico, has eight (8) floors, with each floor having exactly thirty (30) rooms.
Hotel management has contracted you to create a Visual Basic application, named Hotel Occupancy. This application is required to calculate number of rooms occupied in each floor at any given time, plus its occupancy rate. The occupancy rate is the percentage of rooms occupied, and may be calculated by dividing the number of rooms occupied by the total number of rooms on a floor. For example, if 18 rooms of the total of 30 rooms are occupied on the first floor, the occupancy rate for that floor will be18/30 = 0.6 or 60%.
[Please note that the number of rooms occupied in each of the eight floors should not exceed 30, and the occupancy rate per floor cannot possibly be greater than 100%]
Finally, at any given time, the application should determine the total rooms occupied, and the overall occupancy rate in the hotel.
Required: Use Named Constants to store the number of rooms per floor, number of floors, and the total number of rooms for all
floor, which is the Maximum Occupancy in the Hotel. Check Class_ Level Scope-Reference page 217).
Now, for maximum occupancy, you can simply multiply the first two named constants, as follows:
(i.e. Constant_(c) = Constant_(a) * Constant_(b))
How it works!
Prior of running the program, the initial display should resemble the figure, as shown below.
The above initial display has a layout with a list box for output; two label controls, two text box controls. The text box controls have their ReadOnly property set as True.
If preferred, you may also use label controls instead of text box controls with their BorderStyle property set to Finxed3D. Finally, three button controls for triggering various actions (event handlers).
Do loop
For …Next loop
Houseman11
Houseman12
Required: When user clicks on Complete Report button, at runtime, a loop (For…Next) should execute and iterate eight times (the number of floors of the hotel). Each time, the loop iterates, it should display an InputBox, to obtain information for one of the hotel’s eight floor’s occupancy (i.e. requesting the user to enter the number of rooms occupied) (Remember, for each of the eight floors, the maximum occupancy per floor is thirty (30) rooms.)
Input Validation: The user should not leave the entry in the Input Box for the number of rooms of each of the eight floors, empty, or enter invalid input. The input required should be in the range of (0 <= n <= 30), and must be numeric (Integer data type. See pp 59-60 in text).
(At runtime, when the user first clicks on Complete Report button, the InputBox, displays Floor 1 as shown below. Here, for example, we have entered 20 rooms for the occupancy of the first floor)
Therefore, the occupancy rate for this floor is 20/30 = 66.67 % (rounded!). The above process will repeat eight (8) times, for each of the eight floors, and each time the user enters a value for the number of rooms of a particular floor, the number should be within the range (0 <= n <= 30). the occupancy rate should be automatically computed and displayed for each floor. The occupancy rate for each floor must be in the range of (0.00% <= occupancy rate <= 100%).
**Caution** In case of invalid entry by the user (i.e. number of rooms per floor n > 30, you may then use a “Message Dialog Box to warn the user with a brief message.
The following display depicts the number of rooms occupied in each of the eight floors, and the occupancy rate: Additionally, the total number of rooms and overall occupancy rate.
To achieve the desired results for the above display, you should implement a Do … , or , within the For…Next loop, as follows
:
].
Required: For effective visual display at the time of the output,
please use “Courier New font “, which should correctly align the text in the list box.
Required:
loop
While… End While loop
[Best Practices
For clarity, and readability, make sure you will clear the list box, and other
appropriate controls on the Form, each time, you will need to generate new floor occupancy data
‘ Display a message to the user indicating that the
Houseman13
Further discussion clarifying the required tasks that should be completed
1. As stated previously, use an InputBox, to request number of rooms occupied in each of the eight floors. You should consider the validity of the data entry (i.e. the user enters a value for the number of rooms of a particular floor, the number should be within the range (0 <= n <= 30), (‘Do not continue to the next floor unless the value inputted by the user is a numeric within required range). In case of the invalid entry by the user, (
).
2. Also, within the For...Next loop, the following computation should be carried out.
(a) ‘Calculate the occupancy rate for the current floor.
(b) ‘Output the data for the current floor to the list box.
(c) ‘Keep a running total of the rooms occupied for all the floors.
: After the For...Next loop complete its execution, (' Display the results to ), using text box objects or labels (see above) to depict the total number of rooms
occupied by the hotel, as well as the overall occupancy rate.
Required Tasks: When the user clicks on the Clear button, all the appropriate controls on the
form should be cleared. [ : ].
Required Tasks Finally, the Exit button should end the application.
Recommended naming convention: For control objects appearing in the Code Editor.
input for the current floor is not valid.
Required Tasks
the user.
Best Practices
For clarity, and readability, make sure you will clear the
list box, and other appropriate controls on the Form, each time, you will need to generate new
floor occupancy data
Name Property
Text Property
Control Type
Description
frmHotel Hotel Occupancy GroupBox1 Floor Occupancy Data box
lstFloorOccupancyData
lblTotalRooms Occupied * lblOverallOccupancyRate *
Form Group Box
List Box Label Label
Button
Button Button
Holds application’s controls
passive object (not used in code) to hold the list
Displays floor occupancy data
Displays the total number of rooms occupied Displays the overall occupancy rate
Should initiate the start of the hotel occupancy project. and when triggered it will display eight
Input Boxes requesting number rooms occupied per floor
When triggered, clears the list box When triggered, the program ends
btnCompleteReport (8)
btnClear btnExit
&Complete Report
C&lear E&xit
Important: *Set the label BorderStyle property to Fixed3D
Remember that in addition of the above, you are required to apply suitable naming convention
to all variables that are declared and used (
accessed in the application
) in the program code.