Lanuage C Beginner level PleaseI need help with this Progra

Lanuage C++ (Beginner level)

Please...I need help with this....

*******************************************************************************************

Program 1 - WRITE ALL THE CODE in ONE FILE... MyArrayPtrArith1.cpp

Step 1 - Define the class Write a class, myArrayClass, that creates an integer array.

* Add an \'arraySize\' variable, initialize to zero ( default constructor function )

* Create int * ptrArray ( default constructor set to NULL )

* Add a default constructor ( see above for what is should do )

* Add a parm constructor that can set the array size, and then assigns new int[arraySize] to ptrArray. Validate size > 0.

* Add a setSize function that lets the user input a size, arraySize, of an array of integers, and then assigns new int[arraySize] to ptrArray ( only if it is NULL ). Validate size > 0.

* Add a function, setAllValues, Have the user prompted and then enter the values for the array. Validate that ptrArray != NULL, if so then add values . Use pointer arithmetic to specify the index of the array while the user is entering the values into the array.

* Add a printAll function that prints out the array...values using pointer arithmetic.

Validate that ptrArray != NULL, if so then print out all values --- testing: - code for int main() --

// Step 2 - Declare and Step 3 use it

// Test default constructor myArrayClass Array1; Array1.setSize(6); Array1.setAllValues();

// Code a Loop that asks for input for each value one at a time

// Input 10,10,20,25,30,35,42 Array1.printAll();

// Test parm constructor myArrayClass(7) Array2; Array2.setAllValues(); Array2.printAll();

// Test with default constructor myArrayClass * ptrArray1 = new myArrayClass; .......

// add code to call setSize function, use 7 .......

// add code to call setAllValues function: input 100,150,200,250,300,350,420 .......

// add code to call printAll function

Program 2 - WRITE ALL THE CODE in ONE FILE... MyArrayPtrArithTemp2.cpp Convert Program 1 to a template.

Test with and and Use the test found above for program 1…

Program 3 - Split the code from program 2 into two files: MyArrayPtrArithMain.cpp

// contains int main() function and its code MyArrayPtrArithTemp.cpp

// contains class template code and run.

Solution

Answer:

Note: Multiple Questions, I solved the first program please post the other program as separate question

Program code:

//header files

#include<iostream>

using namespace std;

//declares the myArrayClass

class myArrayClass

{

//public Access specifier

public:

   //declares the data members

   int arraySize;

   //declares pointer array

   int * ptrArray;

   //default constructor implementation

   myArrayClass()

   {

        //assigns array to zero

       arraySize=0;

        //assigns the null pointer

       ptrArray=NULL;

   }

   //parameterized constructor Implementation

   myArrayClass(int size)

   {

        //checks the size is greater than 0

       if(size>0)

        {

             //assigns the array size

          arraySize=size;

             //creates a pointer to array size

           ptrArray=new int[arraySize];

       }

     

   }

   //defines the setSize for setting the size

   void setSize(int size)

   {

        //checks the size and the pointer array

       if(size>0 && ptrArray==NULL)

        {

             //assigns the size is array size

           arraySize=size;

             //creates a pointer to array size

           ptrArray=new int[arraySize];

       }

   }

   //defines the setAllValues function

   void setAllValues()

   {

        //getting the values from user

       cout<<\"Enter all values: \";

        //assigns the pointer array to null

       if(ptrArray!=NULL)

        {

             //declares the pointer

           int *ptr=ptrArray;

             //loop to get the values

           for(int i=0;i<arraySize;i++)

             {

                 //getting input as pointer

               cin>>(*ptr);

                 //increments the pointer

               ptr++;

           }

       }

         

   }

   //defines the function printAll()

   void printAll()

   {

        //assigns the array is NULL

       if(ptrArray!=NULL)

        {

             //assigns a pointer array

           int *ptr=ptrArray;

             //loop to print the elements

           for(int i=0;i<arraySize;i++)

             {

                 //printing the values

               cout<<(*ptr)<<endl;

                 //increments the pointer

               ptr++;

           }

       }

        //else statement

       else

        {

             //printing the messages

           cout<<\"No values to print.\"<<endl;

       }

   }

};

//main program for the class

int main()

{

     //defines object for the class

   myArrayClass Array1;

   //calls the function with the created object

   Array1.setSize(6);

    //calls the function with the created object

   Array1.setAllValues();

    //calls the function with the created object

   Array1.printAll();

   //pauses the console

   system(\"pause\");

   //return statement

   return 0;  

}

Sample Output:

Enter all values: 100 150 200 250 300 350

100

150

200

250

300

350

Press any key to continue . . .

Lanuage C++ (Beginner level) Please...I need help with this.... ******************************************************************************************* Prog
Lanuage C++ (Beginner level) Please...I need help with this.... ******************************************************************************************* Prog
Lanuage C++ (Beginner level) Please...I need help with this.... ******************************************************************************************* Prog
Lanuage C++ (Beginner level) Please...I need help with this.... ******************************************************************************************* Prog
Lanuage C++ (Beginner level) Please...I need help with this.... ******************************************************************************************* Prog

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site