# Homework 1 SwapP and SwapR

\$30.00

Category:
Rate this product

EECE7205: Fundamentals of Computer Engineering
Homework 1
Problem 1 (30 Points)
Write a C++ program to implement and test two functions: SwapP and SwapR.
1. SwapP swaps the values of two integer variables using pass-by-pointer.
2. SwapR swaps the values of two integer variables using pass-by-reference.
Write a main function in your program to test these two functions.
Problem 2 (30 Points)
The following main function of a C++ program calls the function MaxFirst that moves
the maximum value in a pre-initialized array v of integers to the beginning of the array.
The contents of the array are displayed on the screen after that change.
int main()
{
// Declare array
int v[] = {6, 1, 7, 8, 2, 5};
// Bring Max value to beginning
MaxFirst(v, 6);
// Print array
for (int i = 0; i < 6; i++)
cout << v[i] << ‘ ‘;
return 0;
}
Implement the function MaxFirst in C++. The function brings the maximum value in the
array to the first index of the array (i.e., v[0]) and moves the other contents as needed.
Your algorithm must work on the given array without defining any other temporary arrays
and for any array size. For the above example, the program will display “8 x x x x x”
on the screen where the x’s represent the other numbers (6, 1, 7, 2, 5) in any order as
needed by your algorithm. Do not use the swap function provided by the language library.
EECE7205 – Homework 1
3 / 3
Problem 3 (40 Points)
Write a C++ program that takes as inputs from a teacher, the names of her/his students
along with the grade of each student in an exam. Define a struct with two fields: Name
and Grade. In your program, the main function creates an array of this struct to store the
students’ data. All grades are integers that have to be in the range from 0 to 100
(inclusive). Assume no two grades have the same value and there are at least six students
in the class. At the beginning, you will need to ask the teacher for the size of the class (the
number of students) and use dynamic memory allocation to create the array.
The program will display (as its outputs) the following:
1. The average and median of the students’ grades.
2. The name and grade of the three students with the maximum three grades.
3. The name and grade of the three students with the minimum three grades.
Each one of the above four outputs must be implemented in a separate function where
the array is passed to these functions as a parameter. Do not use any global variables in