Write a CC program that uses a random N generator to create

Write a C/C+ program that uses a random N generator to create a vector of N random numbers between the limits of MIN and MAX, have your program use for loops and else if loops to sort the random numbers into the following bins: Bin A: .9*MAX

Solution

C++ code:

#include <bits/stdc++.h>
using namespace std;

int main()
{

int N = 333;
int low = 0; int high = 1000;
std::vector<int> myvector;
int i = 0;
while(i< N)
{
int tmp = rand()%1000 + 1;
myvector.push_back(tmp);
i++;
}
sort(myvector.begin(),myvector.end());
std::vector< vector< int > > bins1;

std::map<int, string> mymap;
mymap[0] = \"A\"; mymap[1] = \"B\"; mymap[2] = \"C\"; mymap[3] =\"D\" ; mymap[4] = \"E\";
mymap[5] = \"F\"; mymap[6] = \"G\"; mymap[7] = \"H\"; mymap[8] =\"I\" ;

for (int i = 1; i <= 9; ++i)
{
cout << \"Bin \" << mymap[i-1] << endl;
float a = (float(i)/10.0)*float(high);
float b = float((float(i+1)/10.0)*float(high));
for (int j = 0; j < N; ++j)
{
if(float(myvector[j] > a and myvector[j] <= b))
{
cout << myvector[j] << \" \";
}
}
cout << endl;
}
std::vector<int> v;
v.push_back(3); v.push_back(4); v.push_back(7); v.push_back(11);
v.push_back(13); v.push_back(16); v.push_back(32);
for (int i = 1; i < v.size(); ++i)
{
cout << \"Numbers divisible by \" << v[i] << endl;
for (int j = 0; j < N; ++j)
{
if(myvector[j] % v[i] == 0)
{
cout << myvector[j] << \" \";
}
}
cout << endl;
}


return 0;
}

Sample Output:

Bin A
108 118 122 124 125 125 129 132 136 140 144 150 164 168 171 173 173 179 180 184 191 194 198 199 200
Bin B
207 211 212 220 227 228 229 229 230 236 238 246 256 259 271 276 277 281 282 283 287 300
Bin C
302 302 306 306 307 312 314 316 318 321 322 325 325 328 336 337 337 341 341 341 343 344 349 349 351 354 356 363 365 366 368 369 369 369 370 371 373 374 377 379 380 380 384 387 394 396 400
Bin D
404 405 408 413 414 417 419 422 422 423 427 429 430 433 435 435 438 441 442 444 445 445 446 452 453 457 465 466 467 468 469 471 475 482 489 491 492 493 493 498 500
Bin E
501 504 506 506 508 523 527 529 530 531 538 539 540 541 543 543 546 551 552 556 568 568 569 571 583 585 587 587 588 591 600
Bin F
601 602 606 607 612 614 619 620 623 625 625 627 638 645 650 652 653 660 661 662 669 670 676 677 684 685 689 690 691
Bin G
709 709 710 714 716 722 724 726 730 730 731 733 737 737 740 744 744 747 751 755 757 757 764 764 765 765 772 773 774 777 778 783 785 787 789 794 794 796 797
Bin H
802 803 805 809 811 812 814 815 819 819 820 829 830 841 842 847 847 857 857 858 859 860 863 863 866 872 874 879 882 887 888 895 896 900 900
Bin I
903 905 905 915 916 918 918 920 922 925 926 927 927 928 929 930 931 933 934 937 937 940 941 955 957 960 966 974 981 982 988 997 997 997
Numbers divisible by 4
12 12 20 28 32 44 60 68 72 88 92 96 108 124 132 136 140 144 164 168 180 184 200 212 220 228 236 256 276 300 312 316 328 336 344 356 368 380 380 384 396 400 404 408 444 452 468 492 500 504 508 540 552 556 568 568 588 600 612 620 652 660 676 684 716 724 740 744 744 764 764 772 796 812 820 860 872 888 896 900 900 916 920 928 940 960 988
Numbers divisible by 7
28 35 63 70 91 98 98 140 168 238 259 287 322 336 343 371 413 427 441 469 504 539 546 588 602 623 714 777 805 812 819 819 847 847 882 896 903 931 966
Numbers divisible by 11
44 88 132 198 220 341 341 341 363 374 396 429 506 506 539 583 627 638 660 726 737 737 803 814 847 847 858 957
Numbers divisible by 13
13 91 312 325 325 351 377 429 442 468 546 585 650 676 689 819 819 858 988
Numbers divisible by 16
32 96 144 256 336 368 384 400 896 928 960
Numbers divisible by 32
32 96 256 384 896 928 960

 Write a C/C+ program that uses a random N generator to create a vector of N random numbers between the limits of MIN and MAX, have your program use for loops a
 Write a C/C+ program that uses a random N generator to create a vector of N random numbers between the limits of MIN and MAX, have your program use for loops a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site