Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; int *gdarry(int); //pointer to array int gmode(int *, int); // function for mode void disa(int *, int); // function to display

#include using namespace std;

int *gdarry(int); //pointer to array int gmode(int *, int); // function for mode void disa(int *, int); // function to display the array

int main() { int num; //vairable for number of integers int *ptr; // pointer int mode; // variable for mode cout<<"Please enter the number of integers you want processed: "; cin>>num; ptr=gdarry(num); cout<<" Numbers stored in array ";

disa(ptr,num); //stores num into array mode=gmode(ptr, num); if (mode==-1) cout<<"None of the values repeat "; else cout<<"The most frequent mode value is: " <

return 0; }

int gmode (int *ptr, int num) { int mode =-1; // stopping condition int current; int cnt; for (int i = 0; i < num; i++) //outer loop { current =*(ptr+i); cnt = 0; for (int j=0; j1&&cnt>mode) mode=current; } return mode; }

int *gdarry(int num) { int *ptr = new int [num]; for (int i = 0; i < num; i++) { cout<<"Enter the integer " << (i+1)<< ": "; cin>> *(ptr +i); while(*(ptr + i) <0) //input validation for negative { cout<<"Enter a positive integer " << (i+1) <<":"; cin>>*(ptr +i); } } return ptr; }

void disa (int ptr[], int num) { for (int i = 0; i< num; i++) cout<<*(ptr+1)<<" "; cout<

The array keeps returning the first number inputted instead of the full numbers of the array. For example, input 3 first number is 1 it would display 1 1 1 instead of 1 3 5.

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

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

What are the different categories of financial instruments?

Answered: 1 week ago