1 / 13

STRUCTURES WITH ARRAYS

STRUCTURES WITH ARRAYS. Felipe Navarro Raul Amorin Ashley Dierivo Nicolas Caballero Leony Gonzalez. EEL 2880. GROUP #3. What is a Structure?.

lexiss
Download Presentation

STRUCTURES WITH ARRAYS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. STRUCTURES WITH ARRAYS Felipe Navarro Raul Amorin Ashley Dierivo Nicolas Caballero Leony Gonzalez EEL 2880 GROUP #3

  2. What is a Structure? A structure is a way that we can model real life objects in the programming language by encapsulating all the defining characteristics of the object we are describing into a single data structure.

  3. First Half of Code This statement includes the standard I/O header files for use within the program 2) This statement declares the structure named “donor”. Each donor structure will have a floating point number named “amount” to represent the amount that was donated by said person, a character array named “fname” to represent the person’s first name and a character array named “lname” to represent the person’s last name. 3) This is the main method of the program. 4) This statement initialized a donor structure named “rec”.

  4. Second Half 5) The two printf statements wo strings; One for the first print strings to prompt the user to enter tname and one for the last name. The scanf statement scans the user’s input and stores the strings in the character arrays of the donor structure named “rec”. 6) The printf statement prompts the user to enter the donation amount and the scanf statement scan’s the user’s input and stores the value in the floating point variable of the donor structure named “rec”. 7) The printf statement prints each data member of the donor structure named “rec”.

  5. Code Using Pointers

  6. The Code Output 1 2 3 4 5

  7. Additional Information As you can see from the program, The data members of structures are called by the syntax structure-name.member-name. For example, a structure named “car” may have a data member of type int named “miles” to represent its mileage. This may be accessed with the syntax car.miles.

  8. Block Diagram #include <stdio.h> struct donor{ float amount; char fname[30]; char lname[30]; }; int main(void) { struct donor rec; printf("Enter the donor's first and last names,\n"); printf("separated by a space: "); scanf("%s %s", rec.fname, rec.lname); printf("\nEnter the donation amount: "); scanf("%f", &rec.amount); printf("\nDonor %s %s gave $%.2f.", rec.fname, rec.lname, rec.amount); return 0; } Standard I/O Header Imported Donor Structure Defined Amount First and Last Names Donor “rec” created rec Donor “rec” Assigned First and Last Name rec Donor “rec” Assigned Amount rec Donor “rec” Data Members Printed rec

  9. Similar Program Online struct month { intnumber_of_days; char name[4]; }; static struct month this_month = { 31, "Jan" }; this_month.number_of_days = 31; strcpy( this_month.name, "Jan" ); printf("The month is %s\n", this_month.name );

  10. Another online example

  11. What We Have Learned • Properly declaring a structure. • How arrays can help when using structures. • How to use, declare, and define arrayed structures. • How pointers can be used within these kinds of structures. • The usefulness of arrayed structures for the entering and storage of lists of information of different types that may need to later be recalled. 

  12. Any Questions?

  13. Works cited page • Examples came from: • Example 1: http://ftp.tuwien.ac.at/languages/c/programming-bbrown/c_064.htm • Example 2: http://msdn.microsoft.com/en-us/library/b6fae073(VS.71).aspx • Also Referenced: The Complete Reference by Herbert Schildt

More Related