Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ coding: Below here is my code which to generate 1000 random integers between 1-1000 and give it 11 methods of: 1:output all value 2:sum

C++ coding:

Below here is my code which to generate 1000 random integers between 1-1000 and give it 11 methods of:

1:output all value

2:sum of all value

3:all odd numbers

4:all even numbers

5:output middle value

6:output first value

7:output last value

8:Highest value and its location

9:Lowest value and its location

10:Sort and output

11:linear Search.

But I would like to update my code so it won't generate 1000 random numbers directly in my code. But instead, I will storage the 1000 random number in a (.txt file call random.txt) and utilize a class that will read the 1000 random number data from the (.txt file) then push into an array to allow the program to execute the 11 methods.

/* Here is my code: */

#include #include #include using namespace std;

void bubblesort(int a[],int n){ for(int i=n-1;i>=0;i--){ for(int j=0;j if(a[j]>a[j+1]){ int temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } }

int main(){ srand(time(NULL)); int arr[1000]; for(int i=0;i<1000;i++){ arr[i] = rand()%1001; } int choice; do{ cout<<"1:output all value 2:sum of all value 3:all odd numbers 4:all even numbers "; cout<<"5:output middle value 6:output first value 7:output last value 8:Highest value and its location "; cout<<"9:Lowest value and its location 10:Sort and output 11:linear Search 12:Exit "; cout<<"Enter choice : "; cin>>choice; switch(choice){ case 1:{ for(int i=0;i<1000;i++){ cout< } break; } case 2:{ int sum=0; for(int i=0;i<1000;i++){ sum+=arr[i]; } cout<<"sum = "< break; } case 3:{ for(int i=0;i<1000;i++){ if(arr[i]%2) cout< } break; } case 4:{ for(int i=0;i<1000;i++){ if(arr[i]%2==0)cout< } break; } case 5:{ cout<<"Middle value = "< break; } case 6:{ cout<<"First value = "< break; } case 7:{ cout<<"First value = "< break; } case 8:{ int max=0; for(int i=0;i<1000;i++){ if(arr[i]>arr[max])max=i; } cout<<"maximum value = "< break; } case 9:{ int min=0; for(int i=0;i<1000;i++){ if(arr[i] } cout<<"minimum value = "< break; } case 10:{ bubblesort(arr,1000); for(int i=0;i<1000;i++){ cout< } break; } case 11:{ int data,i; cout<<"Enter item to search in array : "; cin>>data; for( i=0;i<1000;i++){ if(arr[i]==data)break; } if(i==1000)cout< else cout< break; } case 12:{ cout<<"Thank you "; break; } default:{ cout<<"Re enter your choice "; break; } } }while(choice!=12); return 0; }

/* Here is the 100 random number that storage in random.txt 410 321 586 174 590 758 159 482 881 47 523 47 865 200 191 160 254 550 244 386 371 610 32 39 143 702 821 612 659 920 938 382 388 493 534 368 931 264 954 552 539 35 390 458 618 36 743 621 508 668 952 269 509 205 46 216 174 482 112 206 890 19 7 162 152 520 51 70 795 894 590 446 969 960 661 155 113 704 259 52 185 134 232 744 327 88 123 119 526 579 148 233 131 8 413 966 968 411 377 56 48 944 837 214 220 495 134 699 702 178 700 998 149 84 406 347 480 876 606 674 534 945 422 862 909 801 235 601 298 661 912 782 441 887 846 735 148 639 75 560 17 378 337 67 231 909 953 526 282 592 615 714 272 326 128 173 570 483 169 243 343 559 217 456 845 763 474 953 273 649 604 731 649 561 291 468 769 25 818 177 163 669 583 832 778 256 385 999 344 553 223 364 342 649 83 966 253 859 728 180 923 573 72 117 8 695 384 471 601 642 567 716 676 411 253 522 829 527 777 618 121 377 646 804 737 802 695 952 473 800 856 792 625 714 759 372 620 315 362 718 536 221 2 471 957 761 681 810 9 188 745 528 67 499 301 467 702 842 164 199 273 385 186 997 181 633 337 66 902 438 673 143 421 21 851 755 797 375 468 86 333 614 728 671 310 104 61 625 454 154 298 777 700 519 591 603 589 217 942 517 853 183 147 820 770 784 465 326 574 710 989 576 555 134 326 441 28 16 645 846 641 378 65 903 227 818 254 250 657 307 639 727 363 79 626 348 669 46 196 161 550 470 4 335 465 404 532 748 283 466 317 66 719 713 898 314 143 1 672 410 627 71 420 447 206 61 261 695 407 136 788 685 110 694 978 250 824 103 801 650 797 327 117 286 807 848 620 888 926 964 883 156 242 931 435 108 976 938 517 196 240 638 914 72 758 599 526 811 360 632 285 186 104 110 166 336 603 263 751 795 336 708 241 622 285 338 302 128 919 694 169 949 232 159 941 644 582 505 736 569 841 486 528 380 629 504 895 185 233 693 508 345 327 945 874 546 205 762 260 66 403 952 537 185 111 332 397 8 557 211 312 444 235 114 539 936 147 68 744 794 330 666 497 604 665 490 757 262 258 932 550 306 150 977 485 736 412 812 506 683 548 853 967 652 13 292 717 542 324 307 538 562 30 967 793 83 8 800 409 636 668 135 35 72 230 440 958 962 640 280 421 407 772 208 492 777 920 283 927 334 942 292 572 416 972 404 625 742 130 275 129 434 626 148 43 412 373 654 675 128 267 671 222 131 27 996 760 236 900 911 192 896 138 809 758 118 766 344 155 757 159 418 522 490 366 306 62 982 889 106 437 792 805 250 915 255 305 808 882 507 401 257 464 796 400 279 17 27 754 876 6 56 881 909 814 699 86 666 277 495 211 621 587 579 734 233 438 931 880 645 818 671 142 889 391 818 640 1000 116 102 785 647 427 711 127 69 932 325 723 612 263 37 658 502 781 17 501 163 654 991 446 147 840 408 277 934 782 427 50 212 599 601 979 562 897 314 920 626 189 696 949 783 829 217 672 391 219 163 827 73 356 715 52 592 997 463 532 81 908 69 781 490 322 683 656 316 288 369 101 179 672 971 939 307 941 324 507 333 414 671 937 786 30 599 866 207 648 178 532 202 665 410 802 355 454 268 639 94 168 364 398 737 13 913 143 641 961 628 612 322 421 31 20 151 326 660 176 782 1 963 477 495 182 792 201 735 938 644 257 408 802 771 891 483 925 879 439 497 249 83 483 686 608 97 7 39 588 520 390 590 737 593 999 955 746 81 418 661 567 467 807 721 845 975 315 474 894 526 748 74 787 623 40 928 656 791 329 579 87 860 499 6 151 907 769 60 573 515 317 109 675 154 87 362 649 110 223 406 490 646 958 901 257 402 18 729 787 96 921 691 487 273 385 815 851 347 660 315 40 856 577 161 609 791 169 74 263 761 824 382 825 559 461 994 266 19 579 105 540 364 456 318 452 565 582 440 453 416 816 15 754 847 1000 70 326 995 327 234 662 961 908 450 554 954 384 392 887 289 929 783 992 10 574 660 271 994 442 482 654 986 117 713 947 607 272 735 564 751 335 401 214 956 923 227 181 117 361 927 47 478 469 595 537 820 187 710 159 566 207 644 693 225 411 752 84 546 201 225 370 337 474 464 520 980 903 273 450 401 222 456 674 833 647 318 878 105 942 716 564 971 468 343 659 437 586 501 483 751 181 951 568 402 760 567 803 944 766 555 186 759

*/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 11th International Symposium Sstd 2009 Aalborg Denmark July 8 10 2009 Proceedings Lncs 5644

Authors: Nikos Mamoulis ,Thomas Seidl ,Kristian Torp ,Ira Assent

2009th Edition

3642029817, 978-3642029813

More Books

Students also viewed these Databases questions

Question

List behaviors to improve effective leadership in meetings

Answered: 1 week ago