I have looked at another posting from a while back regarding this same question I am about to ask but there was so much going on it did nothing but confuse me so going to ask for myself and see what happens. I need help with my assignment where I have to replace every other element in the array with a lower case x where the array is all letters of the alphabet in upper case letters.
This is the assignment where I have coded for the first two bullet points and am stuck on the third. I cannot figure out how to replace every other element with a lower case x. I have tried what I seen on the other post but with out seeing all of the code I cannot get it to work. In another forum everyone is telling me read this read that and I am getting even more confused. Sometimes it is easier for me understand if I can see the actual code with an explanation of what each portion is doing (not some example that does the same thing...EXACT code) From there I can usually start comprehending and learn from it instead of trying to filter out all the unnecessary fluff.
Reference the following instructions to assist you when completing your Programming Using Arrays and Pointers assignment.
• Using a for loop, print the contents of the array.
The output should appear like this:
PRINTING CONTENTS OF ARRAY
==================================
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
• Change the program logic to prompt you for a position within the array that coincides with the letter. See the example below:
This is the title to your Program related to the alphabet.
Select the number that coincides with the alphabet.
For example, the number 7 should display the letter G.
Enter a number between 1 and 26: 4
The number you selected: 4
The letter related to this number: D
• Then, write the code to update every other element within the array with a lowercase x. The output should appear like the following:
PRINTING CONTENTS OF ARRAY and adding x to every other element
A x C x E x G x I x K x M x O x Q x S x U x W x Y x
• Write the code that will display only the even or odd numbered elements within the array. The output should appear as follows:
PRINTING CONTENTS OF ARRAY USING THE MOD Option
=====================================================
Even Numbered Element = 0 Contents of Element within Array is = A
Even Numbered Element = 2 Contents of Element within Array is = C
Even Numbered Element = 4 Contents of Element within Array is = E
Even Numbered Element = 6 Contents of Element within Array is = G
Even Numbered Element = 8 Contents of Element within Array is = I
Even Numbered Element = 10 Contents of Element within Array is = K
Even Numbered Element = 12 Contents of Element within Array is = M
Even Numbered Element = 14 Contents of Element within Array is = O
Even Numbered Element = 16 Contents of Element within Array is = Q
Even Numbered Element = 18 Contents of Element within Array is = S
Even Numbered Element = 20 Contents of Element within Array is = U
Even Numbered Element = 22 Contents of Element within Array is = W
Even Numbered Element = 24 Contents of Element within Array is = Y
My code that I have so far is this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
char letters [] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '\0' } ;
cout << "PRINTING CONTENTS OF ARRAY" << endl;
cout << "==================================" << endl;
for (int i = 0; i <= 0; ++i)
{
cout << letters << " ";
}
cout << endl;
cout << endl;
cout << "This is the title to your Program related to the alphabet." << endl;
cout << endl;
cout << "Select the number that coincides with the alphabet." << endl;
cout << endl;
cout << "For example, the number 7 should display the letter G." << endl;
cout << endl;
cout << "Enter a number between 1 and 26: ";
int number;
cin >> number;
cout << endl;
cout << "The number you selected: " << number << endl;
if ((number > 0) && (number <= sizeof(letters)))
{
cout << "The letter related to this number: " << letters[number-1] << endl;
system ("pause");
}
else
{
cout << "Sorry, you must choose a number between 1 and 26." << endl;
system ("pause");
cout <<endl;
}
return 0;
}
|
CAN SOMEONE PLEASE HELP ME!