0% found this document useful (0 votes)
17 views7 pages

Sheet 2 (2024 2025)

The document outlines programming assignments for C++ in the Computer Science and Engineering program at Menoufia University for the academic year 2024/2025. It includes tasks related to functions, arrays, pointers, and object-oriented programming, requiring students to implement various algorithms and data manipulations. Each section provides specific problems to solve, emphasizing user input, calculations, and output display.

Uploaded by

youfg56
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)
17 views7 pages

Sheet 2 (2024 2025)

The document outlines programming assignments for C++ in the Computer Science and Engineering program at Menoufia University for the academic year 2024/2025. It includes tasks related to functions, arrays, pointers, and object-oriented programming, requiring students to implement various algorithms and data manipulations. Each section provides specific problems to solve, emphasizing user input, calculations, and output display.

Uploaded by

youfg56
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/ 7

Menoufia University Computer Programming

Faculty of Electronic Engineering AC Year: 2024/2025


Computer Science and Engineering ‫جام عة الم نوف ية‬ 2nd Semester

Sheet [2]: Functions

1. Write a C++ program to first allow a user to input two floating


numbers x and y from K.B. Then, call a function to add the two
numbers, call a second function to sub the two numbers, and call a
third function to multiply the two numbers. Finally, print the results
on the screen.

2. Write program to first allow a user to input two numbers x and y


from KB. Then, call a function to find and return the summation, the
subtraction, and the multiplication of the two numbers. Finally, from
the main function print the results on the screen.

3. Write a C++ program to first allow a user to input an integer


number n from KB. Then, call a function to find and return the
factorial of n. Finally, print the result on the screen.

4. Write a C++ program to first allow a user to input an integer


number n from K.B. Then, call a function to find and return the sum
of the values from 1 to n. Finally print the sum and the average on
the screen.

5. Write a C++ program to first allow a user to input two integer


numbers (A and B) from K.B. Then, call a function to find and return
the sum of the values from A to B. Finally print the sum and the
average on the screen.

6. Write a C++ program to first allow a user to input two integer


numbers (S and E) from K.B. Then, call a function to find and return
the sum of the even values from S to E. Finally print the sum and
the average on the screen.

7. Write a C++ program to first allow a user to input an integer number


n from K.B. Then, call a function called sum() to find and return the
sum of the odd values from 1 to n. Finally print the sum and the
average on the screen.

1
8. Write a C++ program to first allow a user to input three different
integer numbers from K.B. Then, call a function to find and return
the min value. Finally, print the min value on the screen.

9. Write a C++ program to first allow a user to input three different


integer numbers from K.B. Then, call a function to find and return
the largest value. Finally print the numbers and the largest value on
the screen.

10. Write a C++ program to first allow a user to input three different
integer numbers from K.B. Then, call a function called Min() to
find and return the min value and another function called Max()
to find and return the max value. Finally, print the min and the
max values on the screen.

11. Write a C++ program to first allow a user to input an integer


number n from KB. Then, by using recursion, call a function to
find and return the factorial of n. Finally, print the result on the
screen.

« With my best wishes »


Prof. Gamal ATTIYA

2
Menoufia University Computer Programming
Faculty of Electronic Engineering AC Year: 2024/2025
Computer Science and Engineering ‫جام عة الم نوف ية‬ 2nd Semester

Sheet [3]: ARRAYS

1. Write a program to first input 10 values into 1-dimension array


and then print the sum and the average on the screen.

2. Write a program to first input 20 values into 1-dimension array


and then print on the screen the sum and the average of even
values in the array.

3. Write a program to first input 30 values into 1-dimension array


and then print on the screen the sum and the average of the
values in the odd index of the array.

4. Write a C++ program to create an array representing sales of


a week. Enter the sales values of each day of the week and
then calculate the sum and the average of the sales in this
week and print the results on the screen.

5. Write a program to allow a user to input 20 integer numbers


into an array from the keyboard, and then goes through the
array elements, looking for the largest value. Finally, print the
largest number on the screen.

6. Write a program to allow a user to input 30 integer numbers


into an array from the keyboard, and then goes through the
array elements, looking for the minimum value. Finally, print
the minimum value on the screen

7. Write a program to find the smallest and largest values in an


array of 50 integer numbers. Print the on the screen the
content of the array, the smallest and largest values.

1
8. Write a program to input 10 values into an array A and then
compute the values of another array B such that each element
in B represent 5 times of the corresponding element in A.
Finally, print both the arrays A and B on the screen.

9. Write a program to input 30 integer numbers into 1D array and


then print on the screen the contents of the array, the sum and
the average of the values divisible by 5 in the array.

10. Write a program to input the sales of a company in one month


in an array, and then find the average of the sales in the week
and in the month as well as the sum of the sales and finally
print out both the average and the sum.

11. Write a C++ program to first allow a user to input 50 integer


numbers into an array. Then, call a function to find and return
the min and max values in the array. Finally, print the result on
the screen.

12. Write a C++ program to first allow a user to input n integer


numbers into an array. Then, call a function to find and return
the min value and call another function to find and return the
max value. Finally, print the min and the max on the screen.

13. Write a C++ program to first allow a user to input n integer


numbers into an array. Then, call a function to find and return
the sum of the array contents. Finally, print the sum and the
average on the screen.

« With my best wishes »


Prof. Gamal ATTIYA

2
Menoufia University Computer Programming
Faculty of Electronic Engineering AC Year: 2024/2025
Computer Science and Engineering ‫جام عة الم نوف ية‬ 2nd Semester

Sheet [4]: Pointers


1. By using pointers, write a C++ program to input 40 integer values
into an array and then find the smallest value in the array. Finally,
print the array and the smallest value.

2. Write a program to first allow a user to input 50 float numbers into an


array A. Then, by using pointers, search for the address of a number
x that input from the K.B. Finally print the address of the number on
the screen if found.

3. Write a program to first allow a user to input 30 integer numbers into


an array. Then, by using pointers reverse the contents of the array.
Finally, print both the original and reversed arrays on the screen.

4. Write a C++ program to first allow a user to input 50 integer numbers


into array Y. Then, by using pointers, sort the contents of the array
descending order. Finally print on the screen both the sorted and the
unsorted arrays.

5. Write a C++ program to create an array of 20 integer numbers. Then,


by using pointer, input the values of the array from the keyboard. Call
a function called Counter() to count and return number of values
divisible by 5 in the array. Finally, print on the screen the contents of
the array, and the count value.

6. Write a function that accepts an integer array and the array’s size as
arguments. The function should create a copy of the array except that
the element values should be reversed in the copy. The function
should return a pointer to the new array. Demonstrate the function in
a complete program to input n values into the array and print the
original and reversed arrays.

1
7. Write a function that accepts an int array and the array’s size as
arguments. The function should create a new array that is twice the
size of the argument array. The function should copy the contents of
the argument array to the new array and initialize the unused
elements of the second array with 0. The function should return a
pointer to the new array. Show the contents of the arrays on the
screen.

8. Write a function that accepts an int array and the array’s size as
arguments. The function should create a new array that is one
element larger than the argument array. The first element of the
new array should be set to 0. Element 0 of the argument array
should be copied to element 1 of the new array, element 1 of the
argument array should be copied to element 2 of the new array, and
so forth. The function should return a pointer to the new array.
Show the contents of the arrays on the screen.

« With My Best Wishes »


Prof. Gamal M. ATTIYA

2
Menoufia University Computer Programming
Faculty of Electronic Engineering AC Year: 2024/2025
Computer Science and Engineering ‫جام عة الم نوف ية‬ 2nd Semester

Sheet [6]: Object Oriented Programming


[1] By using classes, write a C++ program to calculate the area of Square,
Rectangle, and Triangle. Create three objects (sqr, rect, and tr) of types
(Square, Rectangle, and Triangle) respectively, then input the required
dimensions for each object from the keyboard, and finally display the
area of each object on the screen.
[2] By using classes, write a C++ program to simulate simple calculator that
performs the 4 mathematical operations addition, subtraction,
multiplication and division of two numbers.
[3] Write an OOP complete program to represent a car, the class
constructor will set the values to all its data members then create a
member function outside the class to display the car price, and then
create a function to increase the car price by 1000. The main() program
should create an object. Then display the car price.
[4] Create a class called time that has separate int member data for hours,
minutes, and seconds. One constructor should initialize this data to 0,
and another should initialize it to fixed values. Another member function
should display it, in 11:59:59 format. The final member function should
add two objects of type time passed as arguments.
A main() program should create two initialized time objects and one that
isn‟t initialized. Then it should add the two initialized values together,
leaving the result in the third time variable. Finally it should display the
value of this third variable.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy