Presentation is loading. Please wait.

Presentation is loading. Please wait.

What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.

Similar presentations


Presentation on theme: "What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use."— Presentation transcript:

1 What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use.

2 Program for Previous string empName1, empName2, empName3,… string empLocation1, empLocation2, … cout << “Enter employee name 1:”; cin >> empName1; cout << “Enter Employee name 2:”; cin >> empName2; … //Can we use a loop?

3 Arrays Syntax: type variableName[ size ]; Memory Is Set Aside for size Items of type Each Variable Location in Array Is Accessed by Offsetting into the Array with an Integer Expression Legitimate Offsets Are 0 to size-1 Example: lastname[0] = ‘H’;

4 Array Example char lastname[100]; lastname[0] = ‘H’; lastname[1] = ‘a’; lastname[2] = ‘\0’; cout << lastname[0]; cout << lastname;

5 Array Example int values[15], i = 0; values[i] = 150; values[i + 1] = 78; i = 2; values[i] = 16; cout << values[0]; values[3] = values[0] + 6;

6 Array Example const int ARRAY_SIZE = 100; int offset; int numArray[ARRAY_SIZE]; for(offset = 0; offset < ARRAY_SIZE; offset++) { numArray[offset] = 0; }

7 Array Example const int ARRAY_SIZE = 10; int offset, sum = 0, average; int numArray[ARRAY_SIZE]; for(offset = 0; offset < ARRAY_SIZE; offset++) { cout << “Enter Score ” << offset << “ : “; cin >> numArray[offset]; } for(offset = 0; offset < ARRAY_SIZE; offset++) { sum = sum + numArray[offset]; } average = sum / ARRAY_SIZE;

8 Exam 2 EXAM 2 Lecture Portion Next Monday 20% of Final Grade Know: –loops, switch/case –Files (.open(), >> and <<,.close() ) –Input Failure (cin, cin.clear(), cin.ignore()) –Functions –Arrays

9 Project Posted on blackboard under Tasks Due Wednesday of Finals week at Noon Central Time Hand in to your TA (NOT me!) –.cpp (source code), –.txt (Data file runwaycs105.txt), –.doc (Analysis) Pseudocode!!!!! Design before Coding!!!! Start *TODAY*!!!!

10 Project Do’s Start this week (read project at least) Write Pseudocode (EVERYBODY) Review All cs105 Concepts – Do Well on Final Exam Feel Good about Yourself Explore Your “Inner Geek”

11 Don’t’s No Working Together Write Your Own Code!!! Checked by Supercomputer May be Called in to Discuss Program Last Term – 10 Investigated, 7 0s, 1 probation Nine terms (74 investigated, 44 received 0s)

12 Initializing Arrays int main() { char cArray3[5] = {'a', 'b', 'c'}; int iArray[] = {1, 2, 3, 4}; int iArray2[10] = {10, 13, 15, 17}; double dArray[] = {3.4, 5.67e4}; double dArray1[5] = {6.7, 7.8, 9.5}; }

13 Initializing string Arrays #include using namespace std; int main() { string sArray[] = {"one", "two", "three"}; cout << sArray[0]; }

14 Two Dimensional Arrays char cArray[10][20]; int iArray[100][50]; cArray[0][0] = ‘a’; cArray[0][1] = ‘b’; cArray[9][19] = ‘x’; iArray[0][0] = 99; iArray[1][5] = 135; iArray[99][49] = 0;


Download ppt "What If? Write a program that prompts for the names and locations of 1000 employees. Store the information in the program for later use."

Similar presentations


Ads by Google