Beruflich Dokumente
Kultur Dokumente
01-05
Lab 10
Purpose:
To create a program that can demonstrate three different uses of pointers function argument,
calling an array and creating a one dimensional array. As well as repeat the program at the users
request.
Program File:
//Lab 10
// CPET Computational Problem Solving I
// Alexander De La Rosa
// Date: 5 May 15
// How to use Pointers
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
//*************************************************************************************************
************************Function
void Function(double *total)
{
*total= 79.9;
cout<<"The New Number is: "<<*total<<endl;
}
int main()
{
char answer= 'y';
bool answerA= true;
int r,number=0, startNumber=0, incrementNumber=0;
char Responds= 'y';
int *array;
double functionNumber=0;
double *total=0;
do
{
//*************************************************************************************************
********************Creation Part
cout<< "Do you want to create something ?: ";
cin>>Responds;
if( Responds=='Y'|| Responds=='y')
{
cout<<"Select the number of elements: ";
cin>>number;
createdArray= new int [number];
cout<<"Select the number you want to start with : ";
cin>>startNumber;
cout<<"Select the number you want to increment with : ";
cin>>incrementNumber;
cout<<endl;
cout<<"This is your Array: "<<endl;
createdArray[0] = startNumber;
for(r=1; r<number; ++r)
{
createdArray[r] = createdArray[r-1] + incrementNumber;
}
//*************************************************************************************************
*****************Array Part
cout<< "Do you want to work with a 9 by 9 Array ?: ";
cin>>Responds;
{
if( Responds=='Y'|| Responds=='y')
{
cout<<"The ARRAY is: "<<endl;
srand(time(NULL));
srand(42); // Use for test data to keep it same everytime you run it
const int ROWS=9, COLUMNS= 9;
int array [ROWS][COLUMNS];
cout<<endl;
if( Responds=='Y'|| Responds=='y')
{
cout<<"Your pick your pointer number: ";
cin>>functionNumber;
cout<< " Your number is: "<<functionNumber<<endl;
Function(&functionNumber);// This is taking the number the user
put and sending it to the function and poiting in the pointer
}
}
//*************************************************************************************************
****************Repetion Part
cout<<"Do want redo the program again: ";
cin>>answer;
if(answer== 'y'|| answer== 'Y')
answerA=true;
else
answerA=false;
}
while (answerA);
system("pause");
return(0);
}
Expected Result:
Part 1User enters 28 elements
Starting Number- 3
Incrementing by 3
Output:
The Array is: 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78,
81, and 84
Part 2Random Array:
Actual Results:
Below is the output to the console when this program is run.
Test Data:
Part 1-
Part 3-
Random Entry: