Lab 08 Program description: Part 1 . Program Description See text book page 468:
ID: 3602686 • Letter: L
Question
Lab 08 Program description:
Part 1.
Program Description
See text book page 468: Programming Problems 1. Total Sales
Part 1:
1.1. Plan your program UI Design: (Use the Designer User Interface document)
You are to come up with an appropriate user interface: This is where you should draw out your design on a sheet of paper and identify each object (name your controls). There are no specific sizes or colors of fonts. You have read enough to this point to where you know how to change all these properties. You must create something that looks “professional”.
1.2. Plan the Event Handler Methods: use Pseudo code, flow charts, etc..
The application should allow the user to click on the “Get Sales” button. The “Get Sales” click event should have the following void method call.
ProcessSalesFile Method: accepts no arguments and does not return anything. This method will open the text file, fill the array, display the array elements in the list box, calculate and display the total sales
Variables must have appropriate data type and meaningful names
Exception handling must be included in this program: Use the try-catch
Appropriate error messages should prompt the user
Output to list box must be a formatted to two decimal places
Output to label must be properly calculated and formatted to two decimal places.
A Clear button should clear everything and set the focus back to the first input box
An Exit button will exit the user out of the program.
1.3. Write the program code:
Create a new project. Call the project yourlastnameLab08_164. Rename the Form1.cs file to DisplaySales.cs (accept all changes if prompted). Change the text on the form to Sales Analysis.
Place and Set the properties of each object, as you have planned.
Before you proceed: Make sure all objects (controls) are properly re-named and properties assigned as instructed.
Build your program to ensure all changes load correctly.
Get the provided Sales.txt file and save in your projects debug folder
Working form the pseudo code, invoke and write each event-handler method.
When you complete the code, thoroughly test the project.
Make several “good” and “bad” input tests to ensure your program performs correctly and handles all user input.
Use books’ examples
Output must be displayed as instructed
Once your program works as desired: get screen shots of your program when running. 1. Of the user interface when it first starts. 2. Of the program with result displayed when the user clicks the Get Sales button.
Part 2.
Program Description:
Once Part 1 is working correctly modify your working program from Part 1 such that it meets the description for Programming Problems #2. Sales Analysis: Text Book page 468. Keep all the function of Part 1. Just add the code logic as follows:
PorcessSalesFlie method will then pass the array in method calls to the appropriate value returning method, and then ProcessSalesFile method will display the returned values in labels on the form.
The application should have the following value-returning methods called from the ProcessSalesFile method.
GetAverage – accepts a double array argument and returns the average of the values in the array
GetHighest – accepts a double array argument and returns the highest value in the array
GetLowest – accepts a double array argument and returns the lowest value in the array
Part 2 Planning:
2.1. Plan your program UI Design:
You are to modify your user interface. This is where you should modify your previous UI design to include and identify each new object (control)
Add a appropriate labels to include control labels for the average, highest and lowest
Reference the books’ examples
2.2. Plan the Event Handler Methods: use Pseudo code, flow charts, etc
When the Calculate button is clicked all of Part 1 should perform as previously instructed. But now your program will call methods to perform the functions as described above. GetAverage, GetHighest, and Get Lowest methods
Identify on your design sheet where, in your outline logic, you are to put the loop logic.
Flow chart or pseudo-code this logic including the output.
Do not attempt to change your UI and code in your program until You understand what you are doing and how/where to add the additional controls and code logic.
2.3. Write the program code:
Place each new object and Set their properties as you have planned.
Before you proceed: Make sure all new objects (controls) are properly re-named and properties assigned as instructed.
Build your program to ensure all changes load correctly.
Working form the pseudo code, modify the appropriate event-handler method(s). And include the additional methods.
When you complete the code, thoroughly test the project.
Your final application with do the following:
The application should allow the user to click on the “Get Sales” button. The “Get Sales” click event should have the following void method call.
ProcessSalesFile Method: accepts no arguments and does not return anything. This method will open the text file, fill the array, display the array elements in the list box, calculate and display the total sales, then pass the array in method calls to the appropriate value returning method, finally ProcessSalesFile method will display the returned values in labels on the form.
The application should have the following value-returning methods called from the ProcessSalesFile method.
GetAverage – accepts a double array argument and returns the average of the values in the array
GetHighest – accepts a double array argument and returns the highest value in the array
GetLowest – accepts a double array argument and returns the lowest value in the array
Program needs to be in C#
Explanation / Answer
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body
{
font-size:18pt;
}
</style>
<title>Using the FileReader Events</title>
<script type="text/javascript">
var thefile = null;
var reader = null;
var firstProgress = true;
function init() {
var bHaveFileAPI = (window.File && window.FileReader);
if (!bHaveFileAPI) {
alert("This browser doesn't support the File API");
return;
}
document.getElementById("fileElem").addEventListener("change", onFileChanged);
document.getElementById("startread").addEventListener("click", startread);
document.getElementById("abortread").addEventListener("click", abortread);
}
function onFileChanged(theEvt) {
thefile = theEvt.target.files[0];
// display the file data
document.getElementById("filename").innerHTML = thefile.type;
}
function startread(theEvt) {
if (thefile != null) {
reader = new FileReader();
reader.onloadstart = fileLoadStart;
reader.onloadend = fileLoadEnd;
reader.onload = fileLoad;
reader.onerror = fileError;
reader.onprogress = fileProgress;
reader.onabort = fileAbort;
reader.readAsBinaryString(thefile);
}
else {
alert("No file selected to read");
}
}
function abortread(theEvt) {
if (reader)
reader.abort();
}
function fileLoadStart(evt) {
document.querySelector("#readprogress").innerHTML += "<p>File reading started (onloadstart)</p>";
}
function fileLoadEnd(evt) {
document.querySelector("#readprogress").innerHTML += "<p>File reading has ended (onloadend)</p>";
}
function fileLoad(evt) {
document.querySelector("#progCounter").innerHTML = "<p>File read progress: 100%</p>";
document.querySelector("#readprogress").innerHTML += "<p>File reading completed (onload)</p>";
}
function fileProgress(evt) {
// evt will be a ProgressEvent: http://www.w3.org/TR/progress-events/#progressevent
if (evt.lengthComputable) {
if (firstProgress) {
firstProgress=false;
document.querySelector("#readprogress").innerHTML += "<p id='progCounter'></p>";
}
var progCalc = Math.round((evt.loaded / evt.total) * 100);
document.querySelector("#progCounter").innerHTML = "File read progress: " + progCalc + "%";
}
}
function fileError(evt) {
document.querySelector("#readprogress").innerHTML += "<p>A file read error has occurred:</p>";
switch (evt.target.error.code) {
case evt.target.error.NOT_FOUND_ERR:
document.querySelector("#readprogress").innerHTML += "<p>File was not found</p>";
break;
case evt.target.error.NOT_READABLE_ERR:
document.querySelector("#readprogress").innerHTML += "<p>File was unreadable</p>";
break;
}
}
function fileAbort(evt) {
document.querySelector("#readprogress").innerHTML += "<p>File reading has been aborted</p>";
}
window.addEventListener("load", init);
</script>
</head>
<body>
<h1>Using the FileReader Events</h1>
<form action="">
<label>Select a file: </label>
<input type="file" name="files" id="fileElem" />
</form>
<p>File Name: <span id="filename"></span></p>
<p>Read the file content:</p>
<button id="startread">Start Reading</button>
<button id="abortread">Cancel Reading</button>
<p>Read progress:</p>
<div id="readprogress"></div>
<div id="progCounter"></div>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.