PLEASE HELP C++
some of the content in random.txt
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream in("random.txt"); //Opening file
string line; //Hold line by line string from file
int minValue = 2000, second_minValue = 2000, maxValue = -1, second_maxValue = -1;
int nextValue, totalNum = 0, sum_of_elems = 0;
if(in.is_open()) //To check file open or not
{
while(getline(in, line)) //read line by line from file
{
stringstream toNum(line); //to convert string to integer declaring stringstream
toNum >> nextValue; //converting string to int
sum_of_elems += nextValue; //sum of value one by one
if(nextValue < minValue) //to find smallest value
{
second_minValue = minValue; //hold second smallest value;
minValue = nextValue;
}
else
{
if(nextValue < second_minValue) //to find second smallest value
second_minValue = nextValue;
}
if(nextValue > maxValue) //to find largest value
{
second_maxValue = maxValue; //hold second largest value;
maxValue = nextValue;
}
else
{
if(nextValue > second_maxValue) //to find second largest value
second_maxValue = nextValue;
}
totalNum++; //total numbers count
}
//To handle if one value present in file
if(second_minValue > 1000)
second_minValue = minValue;
if(second_maxValue < 0)
second_maxValue = maxValue;
cout << "\n\t\tNumber of Numbers : " << totalNum <<endl;
cout << "\t\tSum of numbers : " << sum_of_elems << endl;
//Average converted to float and precision set to 1 decimal place
cout << fixed << setprecision(1) << "\t\tAverage of numbers : " << ((float)sum_of_elems / (float)totalNum) << endl;
cout << "\t\tLargest number : " << maxValue << endl;
cout << "\t\tSmallest numbers : " << minValue << endl;
cout << "\t\tSecond largest number : " << second_maxValue << endl;
cout << "\t\tSecond smallest number : " << second_minValue << endl;
}
else
{ //If unable to open file display error message
cout << "failed to open file" << endl;
}
return 0;
}
======================================
random.txt
OUTPUT :
PLEASE HELP C++ some of the content in random.txt Program #2 This problem is a modification...
:Pls help for this programing problem in c++ (standard IO without file read/write),better with some comment about why coding that way,thanks Problem A: Counting Numbers Problem Description Write a program that reads numbers from the keyboard into an integer array. You may assume that there will be 50 or fewer entries in the array. Your program allows any number of numbers to be entered, up to 50 numbers. The output is to be a two-column list. The first column is...
Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global variables should be used. PART B: (Statistics Program) – (50%) Please read this lab exercise thoroughly, before attempting to write the program. Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and: Displays the number of groups in the file (5 %) Displays the number of even and odd student...
please read directions first. this is supposed to be a hybrid programe add comments please JAVA please add comments Programming Project 1 and Programming Project 2 "Hybrid" Your goal is to write a program that combines the functionality of both Programming Project 1andProgramming Project 2 into a single program. That is, your program should read a file ( Numbers.txt) of numbers of type double that contains some duplicates and is ordered smallest to largest. Your program should ignore the duplicate...
This is a C++ assignment that I'm trying to create and would like some help understanding while loops, with possible integration of for loops and if statements. This program only uses while, for, and if. I have some code that I have started, but where to go from there is what's giving me some trouble. This is involves a sentinel controlled while loop, and there are a lot of specifications below that I must have in the program. The program...
please put the comment each line, make sure i will have output too. write a program, Summarize (Summarize.java), containing the main() method, that first writes 10,000 random positive double type numbers, to the full accuracy of the number (15/16 decimal places), to a text file named DataValues.txt, one number per line. The program must then close that file, and reopen it for reading. Read back the values from the file and write the following information to a file named Summary.txt:...
This is a C++ assignment that I'm trying to create and would like some help understanding while loops, with possible integration of for loops and if statements. This program only uses while, for, and if. I have some code that I have started, but where to go from there is what's giving me some trouble. This is involves a sentinel controlled while loop, and there are a lot of specifications below that I must have in the program. The program...
Could anyone please help with this Python code assignment? In this programming assignment you are to create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The count of how many numbers are in the file. The average of the numbers. The average is the sum of the numbers divided by how many there are. The maximum value. The...
Please Help! Write a C++ program to read integers until 9999 is entered (called sentinel – sentinel is used to indicate the end of input and must not to be considered as the valid data for the computation). Perform the following operations for the integers entered by the user. Display the sum of the numbers less than 100 Display the smallest of the positive integers Display the largest of the negative integers Display how many integers are between 100 and...
I am in C++ programming, I need help with this assignments. The answer in this assignments when I look for it it doesn't work in my visual studios. Can you please help me? I hardly have C in the class, if I fail I will fail the whole class and repeat this class again. The file named Random.txt contains a long list of random numbers. Download the file to your system, then write a program that opens the file, reads...
Write a C++ program that does the following: Asks the user to enter 3 integers, Obtains the numbers from the user, Prints the largest number and then the smallest of the numbers, If the numbers are equal, prints the message: "These numbers are equal." Prints the sum, average, and product of the 3 numbers.