0% found this document useful (0 votes)
11 views4 pages

Module08-Array Lab 2023

Module 8 Lab focuses on programming with arrays, presenting various tasks that involve user input and output related to heights, numbers, and strings. It includes exercises on calculating averages, checking divisibility, determining pass/fail marks, and comparing strings. Each task emphasizes different programming constructs such as loops and conditionals to manipulate and display data effectively.

Uploaded by

thydaroith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Module08-Array Lab 2023

Module 8 Lab focuses on programming with arrays, presenting various tasks that involve user input and output related to heights, numbers, and strings. It includes exercises on calculating averages, checking divisibility, determining pass/fail marks, and comparing strings. Each task emphasizes different programming constructs such as loops and conditionals to manipulate and display data effectively.

Uploaded by

thydaroith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Module 8 Lab

Copyright of Curtin University


Module 8: Arrays

1. Create a program using array that allows the user to key in and display 5 of their classmate’s
heights (without using any loop constructs).

Please enter 5 heights (in m):


1.75
1.81
1.65
1.52
1.58

The heights entered are:


1.75
1.81
1.65
1.52
1.58

2. Modify the solution from Question 1 to include while loop constructs to shorten the input and
output steps.

3. Modify the solution from Question 2 to allow the program to total up the heights entered and
provide the average height of the group of students.

Please enter 5 heights (in m):


1.75
1.81
1.65
1.52
1.58

The heights entered are:


1.75
1.81
1.65
1.52
1.58

Average height of 5 students is: 1.662

Copyright Curtin University Malaysia 1 Arrays


Module 8 Lab
Copyright of Curtin University
4. Modify the solution from Question 3 to ask the user for the number of heights required. Then, the
program proceeds to total up the heights entered and provide the average height of the group of
students.

Enter number of students required: 3

Please enter 3 heights (in m):


1.75
1.81
1.65

The heights entered are:


1.75
1.81
1.65

Average height of 3 students is: 1.73667

5. Create a program based on the following output. The program assigns 5 numbers (between 1 –
20) and then ask the user to guess any one of the numbers set in the array. Please use arrays
with nested if else constructs to solve this program.

Please enter a number from 1-20: 15

Sorry, your number is not in the list.

Please enter a number from 1-20: 8

Good job! The number 8 is in position 0.

6. Create a program that prompts the user to key in 5 integer values into an array. The program then
displays the list of the integer(s) entered with description of whether the integer is divisible by 3
or not. Sample output is provided below. Please use arrays with for loop constructs to complete
this program.

Please enter 5 integers:


10
15
4
36
2

The integers entered:


10 (not divisible by 3)
15 (divisible by 3)
4 (not divisible by 3)
36 (divisible by 3)
2 (not divisible by 3)

Copyright Curtin University Malaysia 2 Arrays


Module 8 Lab
Copyright of Curtin University
7. Create a program that prompts the user for the number of test marks required. Following that, the
program then requests for the user to key in the required test marks. Once the entering process
is done, the program then lists out all the test marks entered with the indication of whether the
mark is a PASS or FAIL (i.e. Marks >=50 is considered as PASS, Marks<0 or Marks>100
considered invalid). Sample output of the program is provided below. Please use arrays with for
loop constructs to complete this program.

Please enter number of test marks required:4

Please enter the marks:


40
55
65
15

Here are the marks entered:


40 FAIL:(
55 PASS:)
65 PASS:)
15 FAIL:(

8. Create a program that request for the user to enter a single word string. Following that, the
program will display their name with spaces in between the characters entered. Example of the
program output is provided below:

Please enter your name: BigFoot

Name entered is: B i g F o o t

Use the concept of array with while loop construct to complete this program.

9. Create a program that requests for the user to enter a multi-word string. Following that, the
program will determine the number of words entered by the user based on the number of spaces
appeared in between the words. Example of the program output is provided below:

Please enter your string:

Big Foot For Life

Your string contains 4 words.

Use the concept of array with while loop construct to complete this program.

Copyright Curtin University Malaysia 3 Arrays


Module 8 Lab
Copyright of Curtin University
10. Write a program that asks a user to enter 2 single word strings. The program then compares both
the strings and displays whether the strings are ‘Equal’ or ‘Not Equal’ as shown below:

Please enter the 1st string: Hello

Please enter the 2nd string: Hello

The strings are equal!

Please enter the 1st string: Hello

Please enter the 2nd string: Bello

The strings are not equal!

Use the concept of array with while loop construct to complete this program.

Copyright Curtin University Malaysia 4 Arrays

You might also like