1. Engineering
  2. Computer Science
  3. hello this is for programming in c below is the...

Question: hello this is for programming in c below is the...

Question details
Hello, this is for programming in C++. Below is the assignment, it deals with pointers and I am a bit lost on them so please include comments when you can. Also, please do not do step 17. Thank you very much.

Creating A Program with Pointers Create a program with filename ptr.cpp as described below. Feel free to compile as you work through this program. The final output is shown at the end of this section. Do not worry about using functions for this part of lab. One long main will suffice. 1. Declare an integer variable named num containing a 5. 2. Declare a variable intPtr that can point to a single int variable, and give it the initial value of NULL 3. After youve declared intPtr and assigned it NULL, have it point to the value stored in num. 4. Multiply the integer pointed to by intPtr by 10. Print out the new integer pointed to by 5. Declare a variable recPtr that can point to a structure of the following type: You will need to use the & as a prefix prior to num. intPtr struct RecType int age float weight; char gender The definition above should of course precede main. 6. Allocate some dynamic memory for recPtr to point to using new.
7. Assign 25 to the age field, 190 to the weight field, and M to the gender field that is pointed to by recPtr. Use the member selection operator (->n each assignment 8. Increment the age field pointed to by recPtr by 5. Print out each of these fields when youre done on the same line separated by a space. 9. Deallocate the memory pointed to by recPtr using delete 10. Make your recPtr variable point nowhere using NULL 11. Declare a variable strPtr that can point to a single char. Initialize it to point to a newly created dynamic array of 50 char elements. Try to do this using one statement 12. Make your strPtr variable point to the string Operating Systems using the strcpy func- tion. Print out the string pointed to by strPtr 13. Construct a for loop that can be used to count the lowercase characters pointed to by strPtr. Do not use array index brackets. Use pointers. Hint: Set up a loop which runs from zero through the length of your string. Use the islower function from the cctype library and the strlen function from the cstring library. The strlen functionis a built-in function that counts the number of characters stored within an array of characters. It works exactly like the string length function we looked at in class except that its already built into the library Print out the number of lowercase letters that are found 14. Add 10 to the base address of strPtr and then print out the string pointed by strPtr 15. Subtract 10 from the base address of strPtr so that t returnsto ts original address. Deallocate the string pointed by strPtr using delete 16. Compile and test your program. You should have output similar to what is shown below inttr points to: Three Fields Pointed to By recPtr strPtr points to LowerCase Letters Pointed To By strPtr14 Printing strPtr after adding 10 50 30 190 м Operating Systems Systems 17. Finally, once you have your program working, go back in and comment out the line near the beginning of your program where you assign to intPtr the address of num. Re-compile and run your program. You should get a segmentation fault since it doesnt have a defined address for intPtr
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution