Please i need someone to help me with the analysis of the assignement below, tha
ID: 3866621 • Letter: P
Question
Please i need someone to help me with the analysis of the assignement below, thank you
Perform a detailed analysis of the differences and similarities between M1 and M2 below
M1
Module 7 example
//only the ones needed
#include <iostream>
#include <conio.h>
#include <string>
#include "M7.h"
using namespace std;
void main()
{
string sName;
const int iArraySize = 5;
int iArray [iArraySize] = {0};
float fArray[iArraySize] = {0.0};
ProgramHeader();//function call for the program header
menu(sName, iArray, fArray, iArraySize);// the menu
system("cls");//clearing the DOS window
Output(sName);//outputing the char array
Output(iArray, iArraySize);//outputing the int array while calling the sort and finding the median
Output(fArray, iArraySize);//outputing the float array while calling the sort and finding the median
cout << " press anyKey to end program...";
_getch();
}//end main
M2
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
inline void nameInputFunction(string name)
{
getline(cin, name);
}
//below is a template function to take user input for an array
//and array is passed here as a pointer
template<typename T>
void functionForArrayInput(T *array)
{
for (int i = 0; i < 5; ++i) //size of array is known and it is 5
cin >> array[i];
}
template<typename T>
void sortArray(T *arr) {
int i, j;
T key;
for (i = 1; i < 5; i++)
{
key = arr[i];
j = i - 1;
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
void display(char name[]) {
cout << "User name is : ";
int i = 0;
while (name[1] != '') {
cout << name[i];
++i;
}
cout << endl;
}
void display(int array[]) {
cout << "Enterd integer array is : ";
int i = 0;
while (i < 5) {
cout << array[i] << " ";
++i;
}
cout << endl;
}
void display(float array[]) {
cout << "Enterd float array is : ";
int i = 0;
while (i < 5) {
cout << array[i] << " ";
++i;
}
cout << endl;
}
int main()
{
string name;
int int_array[5];
float float_array[5];
cout << "Enter user name : ";
nameInputFunction(name);
cout << "Please enter 5 element of int array : ";
functionForArrayInput(int_array);
cout << "Please enter 5 element of float array : ";
functionForArrayInput(float_array);
sortArray(int_array);
sortArray(float_array);
cout << "Your entered int array in sorted order is : ";
display(int_array);
cout << "Your entered float array in sorted order is : ";
display(float_array);
cout << "Median of both array is 3rd element in sorted array ";
cout << "Median of int array is : " << int_array[2] << endl;
cout << "Median of float array is : " << float_array[2] << endl;
return 0;
}
Explanation / Answer
#include <iostream>
#include <conio.h>
#include <string>
#include "M7.h"
using namespace std;
void main()
{
string sName;
const int iArraySize = 5;
int iArray [iArraySize] = {0};
float fArray[iArraySize] = {0.0};
ProgramHeader();//function call for the program header
menu(sName, iArray, fArray, iArraySize);// the menu
system("cls");//clearing the DOS window
Output(sName);//outputing the char array
Output(iArray, iArraySize);//outputing the int array while calling the sort and finding the median
Output(fArray, iArraySize);//outputing the float array while calling the sort and finding the median
cout << " press anyKey to end program...";
_getch();
}//end main
M2
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
inline void nameInputFunction(string name)
{
getline(cin, name);
}
//below is a template function to take user input for an array
//and array is passed here as a pointer
template<typename T>
void functionForArrayInput(T *array)
{
for (int i = 0; i < 5; ++i) //size of array is known and it is 5
cin >> array[i];
}
template<typename T>
void sortArray(T *arr) {
int i, j;
T key;
for (i = 1; i < 5; i++)
{
key = arr[i];
j = i - 1;
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
void display(char name[]) {
cout << "User name is : ";
int i = 0;
while (name[1] != '') {
cout << name[i];
++i;
}
cout << endl;
}
void display(int array[]) {
cout << "Enterd integer array is : ";
int i = 0;
while (i < 5) {
cout << array[i] << " ";
++i;
}
cout << endl;
}
void display(float array[]) {
cout << "Enterd float array is : ";
int i = 0;
while (i < 5) {
cout << array[i] << " ";
++i;
}
cout << endl;
}
int main()
{
string name;
int int_array[5];
float float_array[5];
cout << "Enter user name : ";
nameInputFunction(name);
cout << "Please enter 5 element of int array : ";
functionForArrayInput(int_array);
cout << "Please enter 5 element of float array : ";
functionForArrayInput(float_array);
sortArray(int_array);
sortArray(float_array);
cout << "Your entered int array in sorted order is : ";
display(int_array);
cout << "Your entered float array in sorted order is : ";
display(float_array);
cout << "Median of both array is 3rd element in sorted array ";
cout << "Median of int array is : " << int_array[2] << endl;
cout << "Median of float array is : " << float_array[2] << endl;
return 0;
}