The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Week 4 IT/218
Â
Â
This is the program that is on p. 188
With an array of pointers of type char, each element can point to an independent string, and the
lengths of each of the strings can be different. You can declare an array of pointers in the same
way that you declare a normal array. Let ’ s go straight to rewriting the previous example using
a pointer array:
Â
// Ex4_07.cpp
// Initializing pointers with strings
#include < iostream >
using std::cin;
using std::cout;
using std::endl;
Â
int main()
{
 char* pstr[] = { "Robert Redford", // Initializing a pointer array
 "Hopalong Cassidy",
 "Lassie",
 "Slim Pickens",
 "Boris Karloff",
 "Oliver Hardy"
 };
 char* pstart("Your lucky star is ");
Â
 int dice(0);
Â
 cout < < endl
 < < "Pick a lucky star!"
 < < "Enter a number between 1 and 6: ";
 cin > > dice;
Â
 cout < < endl;
 if(dice > = 1 & & dice < = 6) // Check input validity
 cout < < pstart < < pstr[dice - 1]; // Output star name
Â
 else
 cout < < "Sorry, you haven't got a lucky star."; // Invalid input
Â
 cout < < endl;
 return 0;
}
Â
Appendix CIT/218 Version 31Associate Program MaterialAppendix CReferencethe following instructions to assist you when completing your Programming UsingArrays 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 theletter. See the following example: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: 4The number you selected: 4The letter related to this number: Dï‚·Write the code to update every other element within the array with a lowercasex. The outputshould appear like the following:PRINTING CONTENTS OF ARRAY and adding x to every other elementA 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. Theoutput should appear as follows:PRINTING CONTENTS OF ARRAY USING THE MOD Option=====================================================Even Numbered Element = 0 Contents of Element within Array is = AEven Numbered Element = 2 Contents of Element within Array is = CEven Numbered Element = 4 Contents of Element within Array is = EEven Numbered Element = 6 Contents of Element within Array is = GEven Numbered Element = 8 Contents of Element within Array is = IEven Numbered Element = 10 Contents of Element within Array is = KEven Numbered Element = 12 Contents of Element within Array is = MEven Numbered Element = 14 Contents of Element within Array is = OEven Numbered Element = 16 Contents of Element within Array is = QEven Numbered Element = 18 Contents of Element within Array is = SEven Numbered Element = 20 Contents of Element within Array is = UEven Numbered Element = 22 Contents of Element within Array is = WEven Numbered Element = 24 Contents of Element within Array is = Y
Attachments:
-----------