CISC 1600 Lecture Notes - Lecture 21: Array Data Structure

44 views4 pages

Document Summary

Can determine array size by the size of the initialization list as below or use a size declarator short quizzes[ ]={12,17,15,11}; Array elements can be used in arithmetic operations, in relational expressions, etc. if (principalamt[3] >= 10000) interest = principalamt[3] * intrate1; else interest = principalamt[3] * intrate2; No assignment statement: tests2 = tests; //won"t work. Must instead use a loop to copy element-by-element: for (int indx=0; indx < isize; indx++) tests2[indx] = tests[indx]; Like copying, cannot compare in a single expression like if (tests2 == tests) Use a while loop with a boolean variable: bool areequal=true; int indx=0; while (indx < isize){ if(tests[indx] != tests2[indx] areequal = false; index++; Use a loop to add together array elements double average, sum = 0; for (int tnum=0; tnum < isize; tnum++) sum += tests[tnum]; //accumulating the sum each time average = sum/isize; // function prototypes void doublearray(int [ ], int); void showvalues(int [ ], int);

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents