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...
Write a program in C that reads 20 float numbers from a file. The values are stored in a vector (1-dimensional array). Find and display the smallest number, the second smallest number, and the third smallest number of the set. Use only these libraries: stdio.h, stdlib.h, math.h, and string.h. Below is an example of the input file (in1.txt) and the resulting output file (output.txt). In1.txt: 3.14 4.05 -3.73 4.13 1.32 -2.21 0.46 4.57 4.64 -3.42 4.57 -0.14 3.00 -3.58 -0.78...
: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...
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...
I have an assignment in C# due and I am unsure of where to even begin. Assignment: Write a C# console app that will input a text file of numbers. For these numbers, find the number of numbers (one per line), the largest of these numbers, the smallest of these number, and the average of these numbers. I'm attaching two files, a short file with the numbers 1 thru 9 for testing and another larger file for the actual processing...
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:...
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...
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...