1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anon25 [30]
3 years ago
14

Number Analysis Program: Write a program that reads data from the text file numbers.txt. Assume the file contains a series of nu

mbers, each written on a separate line. The program should read the numbers from the file and store them into the array numbers. Then program should display the lowest value, the highest value in the array. Also calculate and display the average of these values.
Computers and Technology
1 answer:
diamong [38]3 years ago
8 0

Answer:

See Explaination

Explanation:

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

// namespace std

using namespace std;

// start of the main function

int main() {

// setting precision to 2 decimal point

cout << fixed << setprecision(2) << endl;

// variable declration

int i, count = 0;

int min, max, value, arr[100];

double sum = 0;

double Avg;

// file object creation

ifstream infile;

string file;

// input the file name to read

cout << "Please enter the name of the file to read numbers for Number "

"Analysis program "

<< endl;

getline(cin, file);

infile.open(file.c_str());

// check if file exist or not

// and loop untill you get correct file name

// if you do not want to loop again and again then

// simply return 0; from code

if (infile.fail()) {

cout << "Error opening the file." << endl;

return 0;

// cout << "Please enter the name of the file to read numbers for Number "

// "Analysis program "

// << endl;

// getline(cin, file);

// infile.open(file.c_str());

}

// start reading the data from the file

while (infile >> value) {

arr[count] = value;

count++;

}

// initialize min max to arr[0]

min = max = arr[0];

// find the lowest element

for (i = 0; i < count; i++) {

if (arr[i] < min) {

min = arr[i];

}

}

for (i = 0; i < count; i++) {

// find the highest element

if (arr[i] > max) {

max = arr[i];

}

}

for (i = 0; i < count; i++) {

// calculate sum

sum = sum + arr[i];

}

Avg = sum / count;

// display output

cout << "The highest value is " << max << endl;

cout << "The lowest value is " << min << endl;

cout << "The sum of the numbers is " << sum << endl;

cout << endl;

cout << "The average of the numbers is " << Avg << endl;

return 0;

} // end of the main program

You might be interested in
Which code snippet is the correct way to rewrite this in Semantic HTML?
xxMikexx [17]

Answer:

<div id="header">

<h1>Waketech</h1>

</div>

<header><h1>Waketech</h1></header>

Explanation:

I think thats the answer your welcome

8 0
9 months ago
What is blockchain? How it works? I heard bitcoin uses it.
igor_vitrenko [27]
Https://www.toptal.com/bitcoin/blockchain-technology-powering-bitcoin
i dont have the time to read it right now, but i was able to find you this link that should hopefully help- you out!
6 0
3 years ago
Who is the father of computer?​
bagirrra123 [75]

Answer:

The first automatic digital computer has been designed by the English mathematician and inventor Charles Babbage. Babbage developed the Analytical Engine Plans for the mid-1830s.

Explanation:

  • Babbage has developed the concept of a digital, programmable computer and was a mathematician, philosopher, inventor, and mechanical engineer.
  • Some regard Babbage as a "computer father"
  • The inventing of its first mechanical computer, the difference engine, is attributable to Babbage, which eventually resulted in more complex electronic designs, although Babbage's Analytical Engine is the main source of ideas for modern computers. He was described as the "prime" among the numerous polymaths of his century by his varied work in another field.
7 0
2 years ago
Write a program that unpickle's employee dictionary and while reading from the dictionary, it allows users to lookup an employee
melamori03 [73]

Answer:

Check the explanation

Explanation:

from Employee import *

import pickle

import random

def unpickle_employee(filename):

file=open(filename,'rb')

data=pickle.load(file)

file.close()

return data

def pickle_employee(data,filename):

file=open(filename,'wb')

pickle.dump(data,file)

file.close()

if __name__=='__main__':

filename="Employees.dat"

'''

E=Employee("Ajay",1,"R&D","Manager")

data={}

data[1]=E

pickle_employee(data,filename)

'''

data=unpickle_employee(filename)

 

while True:

print("\nData In Employee.dat")

for d in data:

print("Employe data: ",data[d].get_name(),"({},{},{})".

format(data[d].get_id_number(),data[d].get_department(),data[d].get_job_title()))

 

print("\n\n\t\tMenu")

print("To add new Employee, Enter a")

print("To update any Employee, Enter u")

print("To delete any Employee, Enter d")

print("Enter anything to quit")

choice=input("Enter: ")

if choice=='a':

id_number=random.randrange(100,200,1)

while id_number in data:

id_number+=1

if id_number>=200:

id_number=100

name=input("Enter the Name: ")

department=input("Enter the Department: ")

job_title=input("Enter the job title: ")

E=Employee(name,id_number,department,job_title)

data[id_number]=E

elif choice=='u':

id_number=int(input("Enter the Employee id_number to update: "))

for d in data:

print(id_number,d,d==id_number)

if id_number in data:

print("Employe data: ",data[id_number].get_name(),"({},{})".

format(data[id_number].get_department(),data[id_number].get_job_title()))

print("\nPlease Enter the details")

name=input("Enter the Name: ")

department=input("Enter the Department: ")

job_title=input("Enter the job title: ")

E=Employee(name,id_number,department,job_title)

data[id_number]=E    

else:

print("Employee doesn't exist\n")

elif choice=='d':

id_number=int(input("Enter the Employee id_number to delete: "))

if id_number in data:

print("Employe data: ",data[id_number].get_name(),"({},{})".

format(data[id_number].get_department(),data[id_number].get_job_title()))

choice=input("\nPlease Enter y to confirm, anything else to cancel: ")

if choice=='y':

del data[id_number]

else:

print("Employee doesn't exist\n")

else:

break

pickle_employee(data,filename)

7 0
3 years ago
Sherri is considering replacing a processor on her laptop. The laptop is running slower than she would like. What should Sherri
Schach [20]

Answer:

Option b, Option c, and Option d  are the correct options.

Explanation:

While Sherri is replacing the laptops processor because her's laptop working slow as compared to the past performance then, she decided to ensure to use the right processors for her laptop's motherboard. Then, she verifies that not under the warranty, and she also determines that the teardown procedure is available or not.

4 0
3 years ago
Other questions:
  • What are some measurements used to determine water waste from leaking faucets?
    10·1 answer
  • What’s good and bad about having social media?
    14·2 answers
  • Read the excerpt from The Code Book. Other attacks include the use of viruses and Trojan horses. Eve might design a virus that i
    13·1 answer
  • Computer hardware without software is useless while computer software without hardware is meaningless. Discuss. Plz provide exam
    15·1 answer
  • A newly opened law firm in Kirkland decides to create a small website that provides a brief introduction of the firm, its missio
    8·1 answer
  • George wants to pursue a career in web technology as a web developer. Which certifications can help him as a web developer?
    5·1 answer
  • What best describes "broadband access"?
    13·1 answer
  • What are your thoughts on copyright?<br><br> (Write 2 or more sentences)
    9·2 answers
  • 16. A/An __________ is operated on the principle that the dying have special needs and wants that hospital personnel are too bus
    15·2 answers
  • Question #1
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!