200 likes | 285 Views
Documenting a Structure in C. Explaining a Structure Build. Problem solving:. What defines a Student? In what ways can a students information be collected?. This student name can be Tim who is 21 years old and has an ID of 5869403. The Students name is Tim His age is 21 5869403 is his ID.
E N D
Documenting a Structure in C Explaining a Structure Build
Problem solving: • What defines a Student? • In what ways can a students information be collected?
This student name can be Tim who is 21 years old and has an ID of 5869403. • The Students name is Tim • His age is 21 • 5869403 is his ID
What does the program do?: The program creates a structure array model to gather information from a student. The information is gathered and printed.
Create Structure Define Structure Variables Define Values in the structure Print out the Values contained in the Structure
Sequence: main() ●Declare: Structure for Student ●Initialize: Variables Student Tim contents ●Print out the Students information
Creating a Structure Donation Donator
Declaration of Structure Initialize Variables and Arrays Within Structure Instance 1 Instance 2 Call Structure Within Main Function Pointer to Structure Within Main Function Print Dialogue and Scan for Input (Name) Print Dialogue and Scan for Input (Value) Print Recorded Character Strings and Final Dialogue
Declaration: struct donor Initialize: • Float for donation amount • Character Array for First Name • Character Array for Last Name
Sequence: main() • Call Structure • Print Dialogue Asking for Donor’s First and Last Names • Scan Input Information and Store Within Character Arrays in Structure • Print Dialogue Asking for Donation from Donor • Scan Input Value and Store Within the Float in Structure
Sequence: main() [cont.] • Print Final Dialogue, Denoting Donor’s First and Last Names • Retrieved from Character Strings from Structure • Print Donation Amount Pertaining to Donor • Retrieved from Float • Specify Decimal Places
The main difference between the two blocks of code is the utilization of a pointer. The new line of code can only be read in C++, due to it using the new operator. The new operator returns a non-zero pointer to the object. Also, the pointer version of the code utilizes the -> pointer operator rather than the . operator. Either of these operators would successfully retrieve a pointer. Otherwise, the two blocks of code function identically and display the same command dialogue when prompted.