Question

In: Computer Science

Use Visual Basic Language In this assignment,you will create the following data file in Notepad: 25...

Use Visual Basic Language

In this assignment,you will create the following data file in Notepad:

25

5

1

7

10

21

34

67

29

30

You will call it assignment4.dat and save it in c:\data\lastname\assignment4\. Where lastname is your last name.

The assignment will be a console application that will prompt the user for a number.

Ex. Console.Write(“Enter a number: ”)

And then read in the number

Ex. Number = Console.ReadLine()

You will then read the data file using a while statement. For each time you read a value from the data file you will compare it to the user input value.

Ex. User inputs the value “10”. The first value from the data file is “25”. 25 is greater than 10, so the output would look like this, “25 is greater than10”. The next value from the data file is “5”, so the output would be “5 is less than 10”.Also check for equal values as well.

You will also total the values from your data file and then average them at the end. Your total will be 229 and the average will be 22.9. The total variable should be a double and rounded to two decimal places. The results should be printed to the screen at the end of the program.

Required elements:

* Comments and documentation

* Data file

* While statement(read the data file)

* Totaling the contents of the data file

* Averaging the total

Variables needed:

* Number (input from the screen): Type Double

* Datanumber (input from the data file): Type Double

* Total (values totaled from data file): Type Double

* AverageData (Average from the total): Type Double

* Const variables of string type: For example:

Const author As String = "Jack"

Const doublelines As String = "=============="

Solutions

Expert Solution

//IF YOU ARE SATISFIED WITH THE CODE, KINDLY LEAVE A LIKE, ELSE COMMENT TO CLEAR DOUBTS

CODE:

using System;
using System.IO;
class MainClass {
public static void Main (string[] args) {
double totalSum = 0; // to get the total sum of the .dat file contents
string line; // used to read the .dat file line by line
Console.WriteLine("\nEnter a number: "); //prompting to input file
int number; // used to input the user value
int readValue; //used to convert the "line" into corresponding integer
int counter = 0; //count the number of values read
number = Convert.ToInt32(Console.ReadLine()); //taking input
// Read the file and display it line by line.
// according to the question file must be saved in the directory specified
// path in the string would be
// "C:\data\lastname\assignment4\assignment4.dat"
System.IO.StreamReader file = new System.IO.StreamReader("assignment4.dat"); //opening file reader
while((line = file.ReadLine()) != null) //while loop used
{
readValue = Convert.ToInt32(line); //converting string to int
if(readValue > number){ //if greater
Console.WriteLine(readValue+" is greater than "+number);
}
else if(readValue < number){ //if lesser
Console.WriteLine(readValue+" is less than "+number);
}
else{ //if equals
Console.WriteLine(readValue+" is equal to "+number);
}
totalSum += readValue; //adding the value
counter++; //counts the number of lines
}
file.Close(); //closing the StreamReader
double average = totalSum/counter; //getting average
Console.WriteLine("\n\nTotal is "+totalSum);
Console.WriteLine("Average is "+average+"\n");
}
}

CODE PREVIEW:


Related Solutions

Use Visual Basic Language In this assignment you will need to create a program that will...
Use Visual Basic Language In this assignment you will need to create a program that will have both a “for statement” and an “if statement”. Your program will read 2 numbers from the input screen and it will determine which is the larger of the 2 numbers. It will do this 10 times. It will also keep track of both the largest and smallest numbers throughout the entire 10 times through the loop. An example of the program would be...
Make a Console application Language should be Visual Basic In this assignment, you will be calculating...
Make a Console application Language should be Visual Basic In this assignment, you will be calculating the two parts for each month. you calculate the interest to pay each month and principal you pay every month. The interest you pay every month = loan * monthlyInterest The principal you pay every month = monthlyMortgage -  interest you pay every month ' what is my remaining loan loan = loan - principal you pay every month Problem 1 : Using While Loop,...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
USE VISUAL BASIC / VB You will create a datafile with the following information: 70 80...
USE VISUAL BASIC / VB You will create a datafile with the following information: 70 80 90 55 25 62 45 34 76 105You will then write the program to read in the values from the datafile and as you read in each number, you will then evaluate it through an if statement for the weather of the day. For example, when you read in the value 70 from the datafile, you should print to the screen that the temperature...
Create a c++ program with this requirements: Create an input file using notepad ( .txt )...
Create a c++ program with this requirements: Create an input file using notepad ( .txt ) . When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File”...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You will be simulating an ATM machine as much as possible Pretend you have an initial deposit of 1000.00. You will Prompt the user with a Main menu: Enter 1 to deposit Enter 2 to Withdraw Enter 3 to Print Balance Enter 4 to quit When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount....
Create a c++ program that: Create an input file using notepad ( .txt ). When testing...
Create a c++ program that: Create an input file using notepad ( .txt ). When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File” marker. Input date...
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for...
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for name, one for hours worked,and the last for hourly rate. The arrays will receive the information from inputs from the screen.For example, you will ask the following three questions: a) Employee name: b) Hours worked: c) Hourly rate: After you have received all ten records and have inserted them into the array, you will then calculate the hourly rate times the hours worked to...
In this project, you will create a Visual Basic solution to perform customer billing at the...
In this project, you will create a Visual Basic solution to perform customer billing at the Cyberian Internet Cafe. Please see below for the detailed instructions. You will create the project and then design a form using the image provided here. Then, add the necessary code to do the billing calculation and display the amount due. Instructions In this case, you will create a Visual Basic solution that performs customer billing for the Cyberian Internet Café. The Cyberian Internet Café...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT