Write a program that creates a file containing TotalCount random integers (in character
format) in the range 0 to HighValue-1. Write PerLine integers per line. Separate each integer
with one space. End each line with the correct line termination for your computer.
The user is prompted for and enters HighValue, which should be an integer larger than zero.
Then the user is prompted for and enters PerLine, which is an integer greater than zero, and
TotalCount, which also is an integer greater than zero. Finally the user is prompted for and
enters the file name.
Construct a Random object and use its method nextInt(int Top), which returns an int in the
range 0..Top-1.
1
Expert's answer
2012-09-14T10:37:26-0400
#include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
int nextInt(int top){ return rand()%top; } int main (){ srand(time(0)); int high,perline,total; cout<<"Please enter High Value\n"; cin>>high; cout<<"Please enter PerLine\n"; cin>>perline; cout<<"Please enter TotalCount\n"; cin>>total; for (int i = 0 ; i < total ; i++){ & if (i % perline == 0) cout<<endl; & cout<<nextInt(high)<<' '; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment