This lab needs a header and .cpp file I have done my .cpp file not sure if it is
ID: 3593504 • Letter: T
Question
This lab needs a header and .cpp file
I have done my .cpp file not sure if it is correct though:
Below is a detailed description of the lab i need done in prep for my project. could someone please compelte this and reply back with the files, please dont post hte actual source code please attach files.
For this lab, we are turning our attention to arrays. An array is a sequential storage unit. So in general it can store more than 1 of a data type. Each element of the array is stored at an index position and those indices start at 0. So for example, if an array has space for 10 ints, they will be stored in index positions 0-9.
Details
You access the individual array elements with [ ] and you put a number in the []. For example, if our array is called myArray and it has size 10, then we could access the first spot like this:
It is an error to put a number that is not within the array indices bounds. It is your job as the programmer to ensure that never happens. This lab is focusing on making sure that doesn’t happen. In my tests, I will be giving you index numbers that are in fact too large or too small.
Input
The input for this program will be a number followed by a character. The number represents the index position where the character is to be stored. You must make sure the given index is valid. If it is, then store the character at the given index location. If it not valid, then don’t do anything.
We will make our array to be of size 30. If an index number is repeated, and it is valid, then we will simply replace what was there.
After you finish reading all the data, you will simply print the entire array in the form shown below.
Output
What is in the output is a header line that indicates what is in the columns below. The first column is the index number and the second column is the contents of the array at the given index location.
As you know, if you don’t initialize a variable, then you don’t know what is in it. Since the data is character data, the array should be of type char. We can use the space character to initialize our array. The space character is ‘ ’ and won’t show anything when printed and can be used to initialize our array. I suggest using a for loop to initialize all 30 index locations to the space character.
Requirements
Below are the requirements for the lab:
You must declare the function void arrayChecking( string input, string output ); in a file named: lab8.h
Your array must be of size 30.
Your array must be of data type char.
You must initialize your array to the space character, ‘ ’
You must implement your function in a cpp file.
Below is my .cpp file
==================================================================
#include
using namespace std;
int main()
{
char myArray[30];
int totalChar, loc;
char indexChar = ' ';
for(int i = 0; i<30; i++)
{
myArray[i] = ' ';
}
cout<<"How many charcters you want to enter"< cin>>totalChar;
for(int j = 0; j {
cin >> loc;
cin >> indexChar;
myArray[loc] = indexChar;
}
cout<<"Index Letter"< for(int k = 0; k<30; k++)
{
cout<
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
cout<<"Please enter your string: ";
string input;
std::string delimiter = " ";
string inventory[30];
//initilizing array with empty space
for(int i = 0; i<30; i++)
{
inventory[i] = ' ';
}
//initilizing variable for position
size_t pos = 0;
std::string token;
//get the input from console
while (getline(cin, input))
{
if (input == "^D")
break;
cout<< "Enter the input line" << endl;
// finding the delimiter "" and positions
while ((pos = input.find(delimiter)) != std::string::npos) {
// get the substring of index position
token = input.substr(0, pos);
input.erase(0, pos + delimiter.length());
int myint1 = stoi(token);
// assigning the index position values with proper values
inventory[myint1]=input;
}
// displaying the array values
for(int i = 0; i<30; i++)
{
cout << i << inventory[i] << endl;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.