63 213
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #14596 in C++ for dfarajzade

Question #14596
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.
Expert's answer
#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)<<' ';
}

system("pause");
return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions