I need help with this project in C++. This is my first computer programing class
ID: 640510 • Letter: I
Question
I need help with this project in C++. This is my first computer programing class so please dont include concept are too difficult for a first timer.
Your project needs to be a minimum of 250 lines.
It must illustrate all the concepts we have covered, most recently being functions and arrays.
1 and 2 dimensional arrays. Passing the arrays between functions. Your functions need to illustrate pass by value, pass by reference, defaulted parameters, returning primitive data types. You need to make sure your output is formatted and you should read and write to files. Sorting game players/searching should also be included.
Explanation / Answer
Passing 1-Dimentional Array to function
Output
Passing 2-Dimentional Array to function
Output
Passing Arguments by Reference
Output
Performing a Search Function
#include
const int MAX=10;
class array
{
private:
int arr[MAX];
int count;
public:
array();
void add(int item);
int search(int item);
};
array::array()
{
count =0;
for(int i=0;i
arr[i]=0;
}
void array::add(int item)
{
if(count
{
arr[count]=item;
count++;
}
else
cout<<" Array is full"<
}
int array::search(int num)
{
for (int i=0;i
{
if(arr[i]==num)
break;
}
if (i==count)
return-1;
else
return i;
}
void main()
{
array a;
a.add(11);
a.add(2);
a.add(9); // function uses the default value of 9
a.add(13);
a.add(57);
a.add(25);
a.add(17);
a.add(1);
a.add(90);
a.add(3);
int num;
cout<<" Enter number to search:";
cin>>num;
int i=a.search(num);
if(i==-1)
cout<<" Number is notpresent in the array";
else
cout<<" The number is at position"<
}
Output
Enter number to search:57
The number is at position 4 in the array.