Lab assignment

I need this code to pass one course, but i don´t know about c programming also I don´t speak English very well. If anyone can send me the solution please i will be infinetly thanked. I don't need learn programming in my career but I am not in my country. I leave here the homework and if anyone can please give me the solution. Thank you very much.

Create an array of double size 100
Repeatdly query the user with the following options

0 - Enter a new number
1 - Modify an existing number
2 - Search for a number
3 - Compute min and max
4 - Compute arithmetic mean
5 - Compute standard deviation
6 - Print all numbers
7 - Quit

Mantain a count of all numbers entered so far
New numbers must be entered at the end of numbers
When searchin, find all occurrences of a number

Like this? I haven't tested this so I'm pretty sure there's a bug or two in it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>

int menu()
{
    int menu_selection;
    std::cout << "0 - Enter a new number\n"
              << "1 - Modify an existing number\n"
              << "2 - Search for a number\n"
              << "3 - Compute min and max\n"
              << "4 - Compute arithmetic mean\n"
              << "5 - Compute standard deviation\n"
              << "6 - Print all numbers\n"
              << "7 - Quit" << std::endl;
    
    std::cin >> menu_selection;
    return menu_selection;
}

void search(double searcher, double* arr, int size)
{
    for (int i = 0; i < size; ++i)
        if (arr[i] == searcher)
            std::cout << searcher << " found at pos " << i << std::endl;
}

double min(double* arr, int size)
{
    double worker = arr[0];
    for (int i = 1; i < size; ++i)
        if (arr[i] < worker)
            worker = arr[i];
    return worker;
}

double max(double* arr, int size)
{
    double worker = arr[0];
    for (int i = 1; i < size; ++i)
        if (arr[i] > worker)
            worker = arr[i];
    return worker;
}

double mean(double* arr, int size)
{
    double worker = 0.;
    for (int i = 0; i < size; ++i)
        worker += arr[size];

    return worker/(double(size));
}

double stdev(double* arr, int size)
{
    double Mean = mean(arr,size);
    double sum = 0;
    for (int i = 0; i < size; ++i)
        sum += (arr[i]-Mean)*(arr[i]-Mean);
    return sqrt( sum / (double(size)) );
}

void print(double* arr, int size)
{
    for (int i = 0; i < size; ++i)
        std::cout << arr[i] << ' ';
}

int main()
{
    double numbers[100];
    int number_size = 0;

    while(true) 
    {
        switch ( menu() )
        {
            case 0:
            {
                std::cout << "Enter your number: ";
                std::cin  >> numbers[number_size++];
                break;
            }
            case 1:
            {
                int index;
                std::cout << "Which index?: ";
                std::cin  >> index;
                std::cout << "What number?: ";
                std::cin  >> numbers[ index ];
                break;
            }
            case 2:
            {
                double searcher;
                std::cout << "Which number?: ";
                std::cin  >> searcher;
                search(searcher, numbers, number_size);
                break;
            }
            case 3:
            {
                std::cout << "min/max: " << min(numbers,number_size) 
                                  << '/' << max(numbers,number_size) << std::endl;
                break;
            }
            case 4:
            {
                std::cout << "mean: " << mean(numbers, number_size) << std::endl;
                break;
            }
            case 5:
            {
                std::cout << "stdev: " << stdev(numbers,number_size) << std::endl;
                break;
            }
            case 6: 
            {
                print(numbers,number_size);
                break;
            }
            case 7: 
            {
                return 0;
            }
            default:
            {
                std::cout << "Wrong input" << std::endl;
                break;
            }
        }
    }
}
Last edited on
Thank you very very much, you are a lifesaver. I will test it and find the bugs (If there are any)
Topic archived. No new replies allowed.