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 { 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 DocumentRight 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

This note was uploaded on 04/17/2008 for the course EECS 168 taught by Professor Miller during the Spring '08 term at Kansas.

Page1 / 3

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online