{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

c++14 April 2008

c++14 April 2008 - delete v void exec(istream& is int n...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
14 April 2008 Assume: double average (double v[], int nV); Double average (double*v, int nv); Void f() { double x[5]={1.1, 2.2, 1.4, 2.8, 1.1}; double avg = average (x, 5); double* p=x; //equivalently: double *p=&x[0]; avg=average(p,5); p[1]=3.7; Dynamically allocated arrays: Example: Read a file that has groups of numbers to be averaged Void readAndAverage(istream &inp) { int n; while (inp>>n) { double *v=new double[n]; for(int i=0; i<n;i++) inp>>v[i]; double avg=average(v,n); cout<<”average=”<<avg<<endl;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: delete v; } } void exec(istream& is) { int n; double* v=readSet(is, n); double* readSet(istream& inp, int& n) { if(inp>>n) { double*v=new double [n]; for (int i=0; i<n; i++) inp>>v[i]; return v; } return NULL; } revisit c-strings void msg(char m) { cout<<m<<endl; } void msg(char* m) { cout<<m<<endl; } int main (int argc, char* argv) multiply dimensioned arrays void func(double M[3][3]) first one is optional...
View Full Document

{[ snackBarMessage ]}