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...
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”...
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...
1. Create a local file on your hard drive by using the NotePad editor that comes...
1. Create a local file on your hard drive by using the NotePad editor that comes with Windows or TextEdit on the MAC. Type into this file some remarks stating that you understand the FTP process. 2. Save it with the name "assign3.txt" 3. Start the FTP program. (SSH for Windows OR FileZilla for MAC) 4. Log on to electron.cs.uwindsor.ca server how do i do this on a mac computer It is intro to internet class
Make a Console application Language should be Visual Basic You will be simulating an ATM machine...
Make a Console application Language should be 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. If the user enter more than...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT