dynamically creating arrays

Discussion in 'C' started by stevec23, Apr 10, 2012.

  1. stevec23

    stevec23 New Member

    Joined:
    Apr 10, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Write the following program in C++

    This program simulates displaying information and performing statistics for a class. You will dynamically create 2 arrays of the same size. One array will hold student numbers, the second array will hold scores. The information for the 2 arrays will come from a file called scores.txt. This file has information for 1000 students. Save the file to your computer for use by your program. Prompt the user of the program for the number of students for which information will be read.

    Note: On my web site in the Assignments section there is an executable version of this program that you can run to see how the program should work. Here is a link to the program: assign7.exe

    You are not required to prompt the user for summary or detailed information. You are also not required to run the program as a loop ( in fact you should avoid this unless you are sure of what you are doing... ).

    Create the arrays as integer arrays. Name your program assign7.cpp.

    Additional Requirements/Notes:

    NO global variables.
    You must create FUNCTIONS for sorting and printing the arrays. You may create additional functions as well.
    You must dynamically allocate the memory for the two arrays

    To dynamically create the arrays, put in a declaration similar to the following: int * number = new int [students];
    To delete the array when you are finished, enter: delete [ ] number;

    See the section on “Dynamic Allocation of Memory” in chapter 8 for more info on dynamic arrays.
    A pointer named number can be used exactly as you would an array called number.

    1. Read in student number and scores from the scores.txt file for as many students as the user specified ( 5-1000 ).
    2. Sort the arrays in ascending order based on the Student Number and then print the information ( one screenful at a time ).
    3. Prompt the user to continue.
    4. Sort the arrays in ascending order based on the Exam Score and then reprint the information ( one screenful at a time ).
    5. Calculate the mean, median and standard deviation of the exam scores.

    If there are an odd number of exam scores, the median is the value of element n / 2 ( e.g. exam[n/2] )
    If there are an even number of exam scores, the median is the average of elements n/2 and n/2-1
    (e.g. (exam[n/2-1] + exam[n/2]) / 2.0 ).

    6. Print the mean, median and standard deviation.

    To calculate the standard deviation, first calculate the sample variance using the following formula:
    ( n is the number of exam scores ).

    ( sum of the squares of the exam scores ) — [ ( sum of the exam scores )2 / ( n ) ]
    ---------------------------------------------------------------------------
    ( n - 1 )

    7. Calculate The standard deviation. The standard deviation is the square root of the sample variance.

    *This is the data that should be contained within scores.txt:

    539 65
    281 72
    472 91
    390 95
    559 78
    782 98
    878 73
    776 72
    846 87
    692 52
    671 60
    335 86
    900 82
    577 62
    724 56
    434 99
    576 61
    400 89
    106 57
    244 56
    439 56
    801 89
    597 80
    501 87
    870 77
    792 88
    237 97
    546 60
    455 91
    727 62
    313 50
    414 56
    256 68
    109 78
    587 76
    989 62
    150 78
    745 96
    450 96
    201 75
    361 75
    141 76
    590 77
    396 77
    217 95
    125 95
    920 71
    67 67
    909 66
    849 61
    854 99
    445 50
    649 100
    832 83
    886 81
    231 65
    154 89
    27 96
    857 62
    764 87
    554 79
    805 97
    430 70
    985 75
    87 71
    947 65
    43 92
    673 66
    873 79
    824 74
    617 74
    934 60
    615 75
    781 72
    70 89
    351 84
    515 66
    827 65
    464 91
    747 60
    694 57
    432 51
    39 68
    107 78
    810 91
    951 51
    839 78
    834 100
    707 85
    122 69
    337 92
    876 56
    605 59
    932 85
    315 60
    97 64
    683 75
    443 79
    323 69
    284 85
    705 64
    205 59
    779 61
    413 54
    112 75
    907 70
    701 82
    967 64
    994 62
    544 69
    630 83
    974 86
    897 78
    95 96
    933 85
    836 55
    202 79
    687 64
    869 65
    240 78
    663 75
    682 60
    978 72
    918 57
    817 50
    69 69
    696 82
    612 66
    153 95
    213 71
    375 58
    403 70
    268 64
    412 87
    631 95
    494 93
    958 65
    927 55
    71 88
    970 89
    320 71
    894 62
    275 85
    321 90
    843 98
    948 50
    226 78
    812 51
    327 65
    596 88
    545 58
    763 52
    525 70
    575 91
    796 82
    167 65
    366 88
    571 86
    195 52
    871 73
    139 51
    695 98
    524 57
    702 84
    526 98
    444 78
    394 95
    531 64
    874 96
    324 51
    518 72
    791 51
    36 59
    79 79
    858 79
    818 92
    24 94
    785 88
    861 97
    393 75
    560 67
    312 83
    186 83
    316 77
    137 100
    295 63
    681 91
    280 74
    984 56
    92 57
    10 68
    908 58
    732 93
    780 67
    803 65
    336 71
    128 66
    291 90
    661 67
    632 66
    550 97
    510 99
    636 96
    485 90
    370 76
    519 80
    864 57
    838 96
    334 92
    19 58
    206 60
    166 54
    887 92
    20 93
    946 95
    465 91
    558 58
    245 73
    601 99
    956 62
    845 86
    376 74
    407 82
    885 62
    786 89
    811 93
    189 81
    565 51
    44 91
    833 67
    165 51
    82 60
    28 80
    239 50
    63 87
    793 69
    491 66
    855 53
    609 75
    120 87
    437 91
    198 88
    273 83
    482 79
    296 79
    658 98
    113 93
    34 56
    406 97
    466 74
    207 68
    190 93
    646 64
    311 50
    136 59
    143 73
    1 98
    246 68
    589 53
    570 57
    263 50
    182 74
    884 93
    583 67
    367 90
    680 71
    353 75
    731 75
    806 81
    955 78
    690 56
    108 73
    119 73
    979 59
    952 66
    794 60
    47 55
    438 57
    300 83
    341 51
    939 72
    362 72
    451 50
    889 80
    48 80
    892 83
    789 89
    426 58
    721 71
    220 95
    672 57
    716 84
    331 61
    7 68
    902 54
    116 50
    197 88
    825 84
    188 93
    965 81
    771 56
    715 66
    529 79
    74 62
    89 76
    52 74
    659 73
    274 79
    807 69
    15 89
    851 82
    303 96
    255 76
    333 88
    579 78
    62 84
    86 71
    737 89
    945 82
    80 57
    569 58
    58 53
    486 84
    347 80
    620 98
    489 85
    761 69
    91 79
    257 81
    991 84
    474 92
    422 76
    584 97
    308 88
    339 90
    138 91
    440 99
    608 66
    460 80
    310 71
    835 79
    940 89
    516 92
    129 52
    234 72
    81 67
    804 67
    262 98
    130 100
    505 71
    227 94
    915 67
    686 66
    734 70
    462 98
    288 62
    447 54
    18 66
    100 93
    29 57
    580 92
    212 50
    483 91
    241 82
    156 89
    456 86
    972 64
    760 85
    232 68
    140 100
    373 97
    101 60
    623 95
    66 62
    922 69
    301 57
    216 55
    117 93
    427 70
    618 86
    641 82
    238 95
    149 83
    622 82
    163 55
    872 79
    669 77
    448 62
    304 77
    287 80
    40 70
    685 50
    926 86
    200 54
    469 55
    148 61
    181 69
    662 74
    398 70
    896 56
    704 68
    286 51
    267 57
    230 68
    477 68
    264 98
    770 61
    277 70
    983 51
    497 52
    512 74
    783 70
    35 57
    551 69
    635 75
    133 96
    363 85
    102 71
    85 66
    9 82
    159 80
    938 87
    346 90
    822 91
    784 59
    61 75
    756 56
    726 80
    976 77
    214 75
    674 93
    552 57
    997 56
    758 65
    865 74
    895 76
    774 81
    192 64
    718 74
    996 85
    648 80
    417 98
    787 55
    513 79
    664 50
    57 50
    733 74
    850 90
    431 97
    640 78
    151 54
    325 90
    748 100
    821 60
    574 59
    329 90
    883 52
    561 89
    478 93
    54 82
    703 82
    752 76
    111 52
    677 56
    937 64
    196 86
    778 77
    553 63
    453 99
    961 60
    762 78
    481 94
    814 91
    314 96
    428 100
    75 96
    709 76
    953 85
    670 66
    898 51
    751 63
    349 89
    750 51
    383 83
    37 86
    710 70
    210 92
    235 95
    317 69
    859 61
    581 61
    567 50
    868 50
    730 84
    604 85
    738 75
    488 82
    911 88
    77 54
    549 93
    271 99
    621 97
    127 72
    928 100
    495 96
    826 61
    259 77
    352 57
    142 78
    46 82
    651 53
    467 75
    160 68
    289 68
    506 66
    11 97
    736 67
    193 61
    556 62
    157 59
    903 67
    73 52
    603 71
    17 91
    819 58
    541 95
    936 57
    260 50
    502 99
    542 71
    954 69
    64 92
    668 80
    146 75
    224 75
    354 74
    473 90
    285 96
    628 84
    508 92
    665 88
    42 54
    619 60
    717 88
    278 68
    942 77
    652 73
    691 70
    225 79
    689 92
    931 93
    174 91
    266 61
    463 82
    480 54
    293 50
    708 77
    425 80
    943 61
    319 72
    913 60
    203 73
    2 72
    950 99
    753 70
    164 53
    562 59
    51 90
    179 91
    924 64
    829 54
    452 94
    848 70
    358 52
    627 81
    904 69
    114 71
    504 67
    322 69
    144 50
    925 62
    713 90
    650 62
    421 82
    32 91
    797 88
    386 82
    384 80
    105 70
    123 61
    815 84
    645 87
    523 75
    222 96
    340 52
    856 66
    409 93
    720 78
    294 56
    219 79
    528 75
    84 93
    389 81
    935 80
    688 99
    514 66
    121 63
    653 60
    517 51
    831 79
    135 88
    454 97
    973 60
    348 54
    591 84
    50 57
    755 90
    276 72
    538 88
    360 95
    511 93
    888 60
    962 59
    916 72
    377 100
    402 83
    678 79
    184 95
    49 95
    126 63
    667 70
    171 100
    722 94
    419 68
    249 81
    298 57
    458 56
    26 73
    461 73
    633 77
    853 86
    302 80
    610 96
    359 50
    966 58
    115 55
    60 80
    626 61
    960 80
    588 91
    880 96
    261 53
    332 82
    769 50
    919 92
    68 65
    12 90
    410 68
    265 96
    543 81
    215 52
    33 57
    372 77
    987 73
    890 80
    968 82
    995 75
    507 51
    614 97
    959 59
    847 57
    676 98
    25 57
    899 58
    55 73
    124 70
    356 88
    441 51
    204 80
    23 65
    93 75
    147 100
    30 58
    228 60
    161 77
    229 84
    176 96
    416 97
    725 100
    479 92
    499 68
    638 73
    509 80
    307 75
    643 70
    350 50
    566 92
    982 82
    788 94
    568 52
    415 88
    693 50
    882 96
    698 87
    158 59
    949 81
    606 66
    684 65
    921 62
    211 71
    593 53
    56 70
    3 80
    243 75
    14 70
    828 62
    740 80
    191 91
    395 83
    168 66
    594 81
    712 71
    744 62
    735 62
    555 74
    866 97
    318 85
    330 88
    391 93
    59 54
    223 61
    837 66
    172 95
    424 72
    741 60
    530 88
    88 76
    540 62
    816 96
    639 55
    777 80
    94 54
    625 68
    242 84
    586 72
    616 93
    759 76
    611 92
    964 83
    666 63
    607 58
    585 94
    76 54
    132 73
    96 82
    252 98
    998 89
    98 88
    446 58
    355 94
    930 67
    808 100
    809 89
    798 64
    564 70
    844 52
    988 87
    644 66
    500 67
    700 52
    13 94
    992 61
    183 68
    22 90
    53 86
    492 83
    800 85
    944 56
    199 52
    423 77
    41 67
    292 66
    236 64
    496 69
    823 59
    145 56
    185 77
    532 91
    382 73
    969 95
    1000 54
    408 94
    326 79
    773 87
    342 99
    65 64
    254 77
    503 60
    484 54
    975 57
    247 50
    392 67
    380 57
    572 89
    719 66
    449 68
    270 79
    162 80
    963 66
    411 50
    218 70
    8 68
    679 78
    418 79
    840 70
    471 74
    290 69
    401 84
    493 83
    420 78
    557 63
    768 63
    766 71
    250 89
    371 93
    457 53
    917 52
    387 62
    729 88
    180 75
    527 73
    476 52
    521 66
    306 71
    299 69
    90 70
    72 85
    385 76
    563 69
    999 54
    981 88
    547 98
    986 69
    634 78
    802 52
    487 57
    378 74
    629 66
    714 52
    283 81
    6 85
    520 58
    742 75
    152 52
    405 55
    155 61
    272 80
    118 53
    879 52
    374 80
    893 93
    906 91
    637 70
    813 100
    534 95
    433 74
    357 77
    21 98
    104 65
    258 68
    78 84
    657 82
    790 66
    775 65
    533 63
    941 98
    746 55
    221 61
    173 68
    841 72
    711 58
    624 84
    912 56
    905 59
    399 64
    600 96
    699 74
    852 69
    602 94
    345 81
    656 66
    881 72
    863 53
    891 55
    772 95
    595 85
    364 86
    248 77
    38 62
    475 54
    980 79
    169 73
    910 63
    548 95
    842 61
    573 84
    253 90
    660 85
    498 50
    305 81
    723 51
    170 61
    739 81
    799 76
    578 83
    365 78
    4 51
    468 80
    654 83
    795 59
    470 51
    99 60
    536 98
    655 74
    754 58
    765 79
    208 68
    297 84
    178 76
    914 65
    269 63
    343 74
    647 74
    697 51
    613 67
    435 98
    338 70
    381 74
    767 75
    83 87
    194 76
    598 67
    369 79
    397 92
    728 92
    820 94
    282 65
    490 72
    187 58
    642 50
    368 59
    706 58
    929 67
    990 75
    251 90
    877 66
    379 63
    867 90
    971 89
    993 75
    743 93
    582 73
    436 67
    309 97
    860 70
    537 89
    830 79
    442 57
    233 88
    31 87
    16 51
    757 84
    177 68
    279 89
    535 98
    110 92
    901 74
    429 51
    328 50
    404 80
    131 77
    957 87
    5 86
    103 88
    388 88
    209 90
    923 78
    459 80
    45 73
    749 54
    134 98
    862 74
    592 51
    344 90
    599 65
    977 91
    175 100
    675 61
    875 88
    522 82
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Hmm, I must have missed the bit in the FAQ that says "just post your homework and we'll do it for you".

    Sarcasm aside, presumably you want help? How far have you got and where are you stuck? Do you understand the requirements?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice