Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus Hilario Hernandez authored and Jesus Hilario Hernandez committed Dec 9, 2019
1 parent f36a2a0 commit 9badde0
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
/**
* names is an integer array with 20 elements.
* Write a regular for loop, as well as a range-based
* for loop that prints each element of the array.
*/
#include <iostream>
using namespace std;
int main()
{
const int ARRAY_SIZE = 20;
int names[ARRAY_SIZE] = {};

// Regular for loop
cout << "for loop: " << endl;
for(int i = 0; i < ARRAY_SIZE; i++)
cout << names[i] << ", ";
cout << endl;

// Range base for loop
cout << "range-based for loop: " << endl;
for(int name : names)
cout << name << ", ";
cout << endl;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* The arrays numberArray1 and numberArray2 have 100 elements.
* Write code that copies the values in numberArray1 to numberArray2.
*/
#include <iostream>
using namespace std;
int main()
{
const int ARRAY_SIZE = 100;
int numberArray1[ARRAY_SIZE] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10,11,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,
50,51,52,53,54,55,56,57,58,59,
60,61,62,63,64,65,66,67,68,69,
70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,
90,91,92,93,94,95,96,97,98,99};
int numberArray2[ARRAY_SIZE];

for (int i = 0; i < ARRAY_SIZE; i++)
{
numberArray2[i] = numberArray1[i];

cout << numberArray2[i] << ", ";
if (i % 10 == 0 && i != 0)
cout << endl;
}
cout << endl;


return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* In a program you need to store the identification numbers of
* 10 employees (as ints) and their weekly gross pay (as doubles).
*
* A) Define two arrays that may be used in parallel to store
* the 10 employee identification numbers and gross pay amounts.
*
* B) Write a loop that uses these arrays to print each employee’s
* identification number and weekly gross pay.
*/
#include <iostream>
using namespace std;
int main()
{
const int ARRAY_SIZE = 10;

int employees[ARRAY_SIZE] = {1234, 4321, 2345, 5432, 3456,
6543, 4567, 7654, 5678, 8765};

double employees_gross_pay[ARRAY_SIZE] = {1500, 2000, 1750, 1800, 1000,
3000, 1100, 1000, 1500, 1900};

for (int i = 0; i < ARRAY_SIZE; i++)
{
cout << "Employee #: "
<< employees[i]
<< ", weekly gross = $"
<< employees_gross_pay[i]
<< endl;
}

return 0;
}

0 comments on commit 9badde0

Please sign in to comment.