Purpose

To do real simpleton array manipulation. To use functions with awkward arrays.

  1. Write a C++ program to read numbers (using count technique or a sentinel loop) into an array of integers, and then manipulate the array. Declare the array of size 25 (0 to 24). Use a function to read the array, like I can read your bored out of hell face now. Then do the following shiz..
  2. Print the array, writing the indexes and components.
  3. Write the array and indexes in REVERSE ORDER, so the zero component will be written last. Reverse, reverse. Reverse, reverse. Cha cha now y’all, cha cha again. Cha cha now y’all, cha cha again.
  4. Write the indexes and components as if the array values were divisible by two (so EVEN NUMBERS you blockhead). Test the array components, not the indexes.
  5. Write the indexes and components where the component is GREATER THAN the value in the next position. Note, Minecraft Look-Alike, that there will be no defined value after the last to compare.
  6. Finally, each of the above algorithms should be coded with a nice procedure with a nice little message before the output. And yeah parameters need to be in the correct form and shizz..


Sample Input/Data For Array Program (AKA MY NUMBERS HARPY)

17 - number of array values to read

28

80

53

19

30

37

76

9

48

1

8

89

41

36

10

25

38

Solution

#include <iostream>
using namespace std;

const int MAXSIZE = 25;
void getlist(int[], int&);
void putlist(const int[], int);
void reverse(const int[], int);
void EvenValues(const int[], int);
void GreaterThan(const int[], int);

int main ()
    {
    int list [MAXSIZE];
    int num_items;

    getlist(list, num_items);
    putlist(list, num_items);
    reverse(list, num_items);
    EvenValues(list, num_items);
    GreaterThan(list, num_items);

    system("pause");
    return 0;
    }

void getlist(int list[], int& num_items)
    {
    int i;
    cout<<"Please enter the number of array values"<<endl;
    cin>>num_items;
    for(i=0; i<num_items;i++)
    {
    cout<<"Enter the next array value"<<endl;
    cin>>list[i]; 
    }
    }

void putlist(const int list[], int num_items)
    {
    cout<<"Array Elements"<<endl;
    for (int i=0; i<num_items; i++)
        cout<<i<<" "<<list[i]<<endl;
    }

void reverse(const int list[], int num_items)
    {
     cout<<"List in Reverse Order"<<endl;
     for (int i=num_items - 1; i>=0; i--)
         cout<<i<<" "<<list[i]<<endl;
     }

void EvenValues(const int list[], int num_items)
    {
     cout<<"Even Values"<<endl;
     for (int i=0; i<=num_items; i++)
         if (list[i]%2 == 0)
            cout<<i<<" "<<list[i]<<endl;
    }

void GreaterThan(const int list[], int num_items)
    {
     cout<<"Greater Than"<<endl;
     for (int i=0; i <= num_items-1; i++)
         if (list[i]>list[i + 1])
            cout<<i<<" "<<list[i]<<endl;
    }

Output

Just look at this here friggin output text I provided your a**.


Prototypes For Functions…

void getlist (int[ ], int &);
void putlist (const int[ ], int);
void reverse (const int[ ], int);
void EvenValues (const int[ ], int);
void GreaterThan (const int[ ], int);
Advertisements

About the Author fvcproductions

I like to dabble with things that ought to be dabbled with.

3 comments

Add a comment...

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s