# SP13 Lab 6 Quizzes .pdf

### File information

Original filename: SP13_Lab_6__Quizzes.pdf
Title: Ain Shams University
Author: Noran

This PDF 1.5 document has been generated by MicrosoftÂ® Word 2010, and has been sent on pdf-archive.com on 19/04/2014 at 00:13, from IP address 197.40.x.x. The current document download page has been viewed 898 times.
File size: 189 KB (6 pages).
Privacy: public file

SP13_Lab_6__Quizzes.pdf (PDF, 189 KB)

### Document preview

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 1

Write a program in which the user enters a 2-D dynamic array in the main(), then the program asks the
user to enter an element, the program then should display the element’s row number and column’s
number if the element is found, otherwise it should display “Not Found”.
Note: Display all occurrences of that element.
Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 2

Write a program that accepts from the user a 2x3 matrix representing the grades of 2 students in 3
subjects, the program then should output a 3x4 matrix containing an extra column for students’ totals,
and an extra row for grades total.
Sample Execution:
Enter the Input Matrix:
Student1
78
82
91
Student2
65
87
79
The Output Matrix is:
Student1
78
82
90
Student2
65
81
79
143
163
169
Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Total of Student
250
225

Section 3

Write a program that counts number of positive and negative numbers of elements entered by the user
in a stored array.
If the array had the following element: 4, 2, 7, 10, 9, 7, 6, 10, -8, 7, 9
Then display the array after being sorted in descending order
Sample Execution:
Number of positive numbers: 10
Number of negative numbers: 1
Sorted array: 10, 10,9,9,7,7,7,6,4,2,-8

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 4

Write a program to fill in a 2-D dynamic array from the user and display it in a matrix form. Then the
program asks to reenter the values of a specific row or column (read them from the user) and then it
displays the modified matrix.
Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 5

Write a program that takes the size of two 2-D arrays , enter their elements, and returns 'true' if the
arrays are equal and 'false' otherwise. The two arrays are equal if all the corresponding elements in
each are equal.

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 6

Write a program that reads the size of an array, its elements and then remove all duplicates from that
array, and displays the resulted array
Sample execution:
Enter the size of the array: 8
Enter the elements: 2,6,8,3,2,3,5,9
After removing duplicates: 6,8,5,9

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 7

Write a program that displays the number of odd and even numbers of elements entered by the user in
a stored array. If the array had the following elements: 4, 2, 7, 10, 9, 7, 6, 10,
7, 9
Then display the array sorted in ascending order
Sample Execution
Even Numbers: 5
Odd Numbers: 5
Sorted array: 2,4,6,7,7,9,10,10

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 8

Write a program that reads two matrices from the user and multiplies them in a new matrix and outputs
the result in a matrix form.
(Hint: Matrix multiplication is done by multiplying matrix 1 rows elements by matrix 2 columns elements,
this means that if matrix 1 size is n x m, matrix 2 size should be m x n and the result is in n x n matrix,
e.g. 2 x 3 * 3 x 2  2 x 2).

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 9

Create a structure Stud having 2 data members: id and grades (array of 6 float). Write a program that
accepts from the user the data of 3 students (id and 6 grades), it then calculates the percentage of the
student and displays his/her data as well as the calculated percentage.
Hint: Assume total grades = 600, i.e. percentage = (sum of students’ grades / 600) * 100.
Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 10

Write a program that asks the user to input the time as a structure including hours, minutes and seconds
reads from the user three times, and then you have to calculate and display the corresponding time in
seconds for each.
Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 11

Write a program that asks the user to enter the number of rows and columns of a 2-D array of integers,
then the array elements. Assume that the size won’t exceed 20 x 20. Then it modifies the values of the
array elements so that each cell will be assigned a new value equals the average of the summation of its
8 neighbors’ values and its value, as follows:
– For example, the new value of cell X = (A1 + A2 + A3 + A4 + X + A5 + A6 + A7 + A8 ) / 9;
– Note: The values of the elements on the array’s border will not be changed.
A1

A2

A3

13

14

A4

X

A5

11

4

A6

A7

A8

12

2

2

3

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

4

5

0

Section 12

Write a program that reads from the user a size and creates an array with this size then enter its values.
The program should try to add each two numbers in the array together and displays their sum
Sample execution:
Enter number of elements
3
Enter 3 elements
157
Sum of 1, 5 is 6
Sum of 1, 7 is 8
Sum of 5, 7 is 12

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 13

Write a program to count number of smaller elements on right of each element in an array. Given an
unsorted array arr[] of distinct integers, construct another array countSmaller[] such that
countSmaller[i] contains count of elements less than arr[i] on the right side of arr[i] in the array. Note
that you have to take first the number of elements from the user.
Sample execution:
Input: 7
12, 1, 2, 3, 0, 11, 1
Output: 6, 1, 2, 2, 0, 1, 0

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 14

Write a program that represents a point as a structure of x and y coordinates. Define a triangle as a
shape that consists of three points, The program is required to read from the user the coordinates of
the three points of the triangle, then check if that triangle has two equal edges.

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 15

Write a program that reads from the user numbers stored in two 1-D arrays, and then the program
should combine and sort the two arrays in a new array and then display it
Sample execution:
First array: 44,20,6,58,3,4,82,9
Second array: 45,3,56,7,98,2,3
New sorted array: 2,3,3,3,4,6,7,9,20,44,45,56,58,82,98

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 16

Write a program that takes the size of an array from the user, reads its elements, then asks the user to
enter two numbers (supposed to be found in the array) and finally calculates and displays the sum of
the numbers between the two numbers – excluding the two numbers themselvesSample execution:
Enter the size of the array: 8
Enter the numbers: 4,7,-3,7,1,-6,3,8
Enter two numbers from the array: 7, 3
Sum of the numbers between 7,3 is: -1

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 17

Write a program that takes two positive integer numbers and calculates the greatest common divisor of
those two integers.
Example:
Greatest common divisor of 40, 50 is 10
Greatest common divisor of 256, 625 is 1
Greatest common divisor of 42, 6 is 6

Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 18

Write a program that takes an array of floating point values; and the size of the array, Then it should
shift the contents of each cell one place to the left, except for the contents of the first cell, which should
be moved into the cell with subscript (size-1) . Thus, for example, if the array looks like this
0.7 | 4.3 | 1.9 | 6.2 | 8.5
then when the array should be changed so that it looks like this
4.3 | 1.9 | 6.2 | 8.5 | 0.7
Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 19

Write a program that reads an array from the user, then the program should reads and integer, and a
flag that represents either “left” or “right” then an integer represents a distance. The program should
locate the first integer in the array and then moves it either to the left or the right (according to the flag)
a number of steps equivalent to the distance.
Hint: moving to the right should returns to first position after the last position
Moving to the left should returns to last position after the first position
Sample execution:
Enter and array: 2,6,5,8,12,4,7,3
Enter an integer: 12
Enter direction: L
Enter distance: 3
Modified array: 2,12,5,8,6,4,7,3
Enter and array: 2,6,5,8,12,4,7,3
Enter an integer: 4
Enter direction: R
Enter distance: 3
Modified array: 4,6,5,8,12,2,7,3
Ain Shams University
Faculty of Computer &amp; Information Sciences
Structured Programming
Lab Exam
First year

Section 20

There are set of 10 employees, each having id, name, hours worked, and overtime hours. The origin
payment for each employee is the hourly rate times the hours worked. The overtime payment for each
employee is one and half of the hourly rate times the overtime hours.
If the hourly rate for all employees is 25.5, write a program that asks the user to enter the data of those
10 employees in the main(), and then calculates for each employee his overall payment, which is the
summation of his origin payment and his overtime payment

Use the permanent link to the download page to share your document on Facebook, Twitter, LinkedIn, or directly with a contact by e-Mail, Messenger, Whatsapp, Line..

Use the short link to share your document on Twitter or by text message (SMS)

#### HTML Code

Copy the following HTML code to share your document on a Website or Blog

#### QR Code ### Related keywords 