Skip to content

Commit b79f397

Browse files
committed
added answer files for C++ Arrays exercises
1 parent 47c4d40 commit b79f397

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* from C++ Arrays: Exercise 1 ( https://www.w3schools.com/cpp/exercise.asp?filename=exercise_arrays1 )
3+
*
4+
* question:
5+
* Create an array of type string called cars.
6+
*
7+
* ______ ____[4] = {"Volvo", "BMW", "Ford", "Mazda"};
8+
*
9+
*/
10+
string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* from C++ Arrays: Exercise 2 ( https://www.w3schools.com/cpp/exercise.asp?filename=exercise_arrays2 )
3+
*
4+
* question:
5+
* Print the value of the second element in the cars array.
6+
*
7+
* ______ ____[4] = {"Volvo", "BMW", "Ford", "Mazda"};
8+
* cout << _______;
9+
*
10+
*/
11+
string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
12+
cout << cars[1];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* from C++ Arrays: Exercise 3 ( https://www.w3schools.com/cpp/exercise.asp?filename=exercise_arrays3 )
3+
*
4+
* question:
5+
* Change the value from "Volvo" to "Opel", in the cars array.
6+
*
7+
* string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
8+
* _______ = ______;
9+
* cout << cars[0];
10+
*
11+
*/
12+
string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
13+
cars[0] = "Opel";
14+
cout << cars[0];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* from C++ Arrays: Exercise 4 ( https://www.w3schools.com/cpp/exercise.asp?filename=exercise_arrays4 )
3+
*
4+
* question:
5+
* Loop through the elements in the cars array.
6+
*
7+
* string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
8+
* ___ (_____ = 0; _ < 4; ___) {
9+
* cout << _______ << "\n";
10+
* }
11+
*
12+
*/
13+
string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
14+
for (int i = 0; i < 4; i++) {
15+
cout << cars[i] << "\n";
16+
}

0 commit comments

Comments
 (0)