please help me i want to make a program that implement functions and arrays using pointers.The user provides an array of integer data, while the system calculates the average ,standard deviation,and median of the array.

i am unable to convert the input data string into separate parts and save into another separate variable.the maximum number of input integers is
50.

Dani AI

Generated

The thread goal was to accept up to 50 integers (entered either one-per-prompt or as a single string) and compute average, standard deviation and median while demonstrating pointer/array usage. was right that reading numbers directly is simplest; when a single-line input is required, the common gap is splitting tokens and validating them. The snippets below show a robust parse-then-stat approach that keeps pointer-based functions while using a safe, resizable container for input.

A small parser that accepts comma- or space-separated integers and stops at a maximum count:

#include <sstream>
#include <vector>
#include <string>

std::vector<int> parseLine(const std::string& line, size_t maxCount = 50) {
    std::string tmp = line;
    for (char& c : tmp) if (c == ',') c = ' ';
    std::istringstream iss(tmp);
    std::vector<int> out;
    int v;
    while (out.size() < maxCount && (iss >> v)) out.push_back(v);
    return out;
}

Pointer-based stat functions (use vec.data() and vec.size() to call them):

#include <numeric>
#include <cmath>
#include <vector>
#include <algorithm>

double mean(const int* data, size_t n) {
    return std::accumulate(data, data + n, 0.0) / n;
}

double stddev(const int* data, size_t n, bool sample = false) {
    double mu = mean(data, n);
    double sumsq = 0.0;
    for (size_t i = 0; i < n; ++i) {
        double d = data[i] - mu;
        sumsq += d * d;
    }
    double denom = n - (sample ? 1 : 0);
    return std::sqrt(sumsq / denom);
}

double median(const int* data, size_t n) {
    std::vector<int> tmp(data, data + n);
    std::sort(tmp.begin(), tmp.end());
    if (n % 2) return tmp[n/2];
    return (tmp[n/2 - 1] + tmp[n/2]) / 2.0;
}

Practical notes: always check n > 0 before calling these; for sample stddev require n > 1. Use double/long double accumulators to avoid integer truncation and overflow. Prefer std::vector or smart pointers over raw new[]/delete[] (if new[] is used, pair it with delete[]). These adjustments address the original parsing issue while keeping the pointer-based function signatures requested by the assignment.

Hi,

I don't understand why are you reading input from the user as a string ? or do you have to ? You can go like this:-

#include <iostream>

using namespace std;

int main(){
          int x = 0;
          cout<<"How many integers you want to enter ? ";
          cin>>x;

          int* arr = new int[x];
          // now calculate the average
          float average = 0.0f;
          for(int i = 0; i < x; i++){

}

}

Sorry, last post was a mistake !!!!!!!!!!

Hi,

I don't understand why are you reading input from the user as a string ? or do you have to ? You can go like this:-

#include <iostream>

using namespace std;

int main(){
          int x = 0;
          cout<<"How many integers you want to enter ? ";
          cin>>x;

          int* arr = new int[x];
          // now calculate the average
          float average = 0.0f;
          for(int i = 0; i < x; i++){
                  average = average + arr[i];
          }

         cout<<"Average is "<<average / x<<endl;
         delete x;

}

Thanx vsha041 u change my mind
i have done the whole programming task successfully i shall post the whole program later

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.