Concept explainers
(a)
Create a Structure inventory which contains the following:
- A character array partName[30]
- An integer partNumber,
- A floating point price
- An integer stock
- An integer reorder.
(a)
Explanation of Solution
Explanation:
A structure is a user defined data type which contains related variables which have same name.
Following syntax is used to create a structure with a keyword struct:
struct <structure name> { variable 1; variable 2; ---; };
Structure named Inventory with the given variables is defined as follows:
struct Inventory { char partName[30]; int partNumber; float pointprice; int stock; int reorder; };
(b)
Define the union data containing char c, short s, long b, float f and double d.
(b)
Explanation of Solution
Explanation:
Union is a user defined data type which contains related variables just like structure which uses same data space for its variable.
Following syntax is used to create an Union data type:
union <union name> { variable 1; variable 2; ---; };
Union named data which contains char c, short s, long b, float f and double d is defined as follows:
union data { char c; short s; long b; float f; double d; };
(c)
Create a structure called address that contains character arrays
- streetAddress[ 25]
- city[ 20 ]
- state[ 3]
- zipCode[ 6].
(c)
Explanation of Solution
Explanation:
A structure is a derived defined data type which contains related variables which have same name.
Following syntax is used to create a structure with a keyword struct:
struct <structure name> { variable 1; variable 2; ---; };
Structure with the name address containing character arrays is defined as follows:
struct address { char streetAddress[25]; char city[20]; char state[3]; char zipCode[6]; };
(d)
Create a structure student that contains the following :
- An character array firstName[15]
- An character array lastName[15]
- variable homeAddress of type struct address.
(d)
Explanation of Solution
Given Information
Structure named address as follows:
struct address { char streetAddress[25]; char city[20]; char state[3]; char zipCode[6]; };
Explanation:
A structure is a derived defined data type which contains related variables which have same name but each variable in the structure has its own data space.
Keyword struct is used to create a structure as follows:
struct <structure name> { variable 1; variable 2; ---; };
Structures can be used to declare variable which can access variables of the structure with the use of following syntax:
struct <structure_name><variable_name>;
Structure name Student which contains a structure
A structure student that contains the variable homeAddress of type struct address along with character arrays firstName and lastName is defined as follows:
struct student { char firstName[15]; char lastName[15]; struct address homeAddress; };
(e)
Create a structure test which contains a 16 bit fields with widths of 1 bit. The names of the bit fields are the letters a to p.
(e)
Explanation of Solution
Explanation:
Bit fields can be defined in the structure which enables user to specify the number of bits a unsigned or int member of variable can store.
Bit fields are defined with the following syntax:
<data type> <bit-field name> <number of bits>
A structure test which contains a 16 bit fields with widths of 1 bit is defined as follows:
struct test { unsigned int a : 1; unsigned int b : 1; unsigned int c : 1; unsigned int d : 1; unsigned int e : 1; unsigned int f : 1; unsigned int g : 1; unsigned int h : 1; unsigned int i : 1; unsigned int j : 1; unsigned int k : 1; unsigned int l : 1; unsigned int m : 1; unsigned int n : 1; unsigned int o : 1; unsigned int p : 1; };
Want to see more full solutions like this?
Chapter 10 Solutions
C How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
- In c++ Create a structure named student with two attributes, name and copa. Define structure variables s1, in the main block(local to main menthod), s2(global), two structure variable as an array. Scan over all four structure variables and display. For example: Test Input Result 1 218CES001 7.1 215001 7.1 218CE500) 7.3 2105004 21BCES003 7.3 218CES004 7.4 7.4 218CE5002 21BC5002 7.2 7.2arrow_forwardC programingarrow_forward2arrow_forward
- Function Description: Given a structure array with fields 'names', 'ASCI and 'points", return the name whose ASCII value is closest to its points (which is the coolest name). Notes: . There will never be a tie for the coolest name. . Do not compute the ASCII value of the names: it is given to you by the ASCII field. . Only the absolute value of the difference between ASCII value and points is considered. Hint: • You can index multiple char values from a structure using (struct.field) Examples: struct1= struct('names". ("Dwayne', 'Justin', "Peters), 'ASCI, (616, 637, 627). "points". (639, 651, 655)); ASCII 2 3 names Dwayne Justin' Peters coolestname = coolestName(struct1) coolestname "Justin' 616 637 627 points 639 651 655arrow_forwardWrite the definition of a pointer to a Rectangle structure. Assume the following structure declaration exists struct Rectangle { int length; int width; };arrow_forwardC# helparrow_forward
- Effects on Size and PaddingA flexible array member is treated as having no size when calculating the size of a structure, though paddingbetween that member and the previous member of the structure may still exist:/* Prints "8,8" on my machine, so there is no padding. */printf("%zu,%zu\n", sizeof(size_t), sizeof(struct ex1));/* Also prints "8,8" on my machine, so there is no padding in the ex2 structure itself. */printf("%zu,%zu\n", sizeof(struct ex2_header), sizeof(struct ex2));/* Prints "5,8" on my machine, so there are 3 bytes of padding. */printf("%zu,%zu\n", sizeof(int) + sizeof(char), sizeof(struct ex3));The flexible array member is considered to have an incomplete array type, so its size cannot be calculated usingsizeof.arrow_forwardQ2 The answer for question Q2(a) – Q2(f) are interrelated. - Write a structure type called car that contains the car's ID, car's model and car's price. (a) (b) Write a statement to declaration an array to store the record of five cars.arrow_forwardCreate a pointer to a Rectangle structure and define it. Assume the structure declaration below exists. Rectangle Structure { length int; width int; };arrow_forward
- Complete C++ the program provided to read football statistics into a structure array, offers a menu to update statistics, print data, and update a file. The program declares a struct to store the data of a football player and has the following data members. The structure in the header file provided: Name Position Number of Touchdowns Number of Catches Number of Passing Yards Number of Receiving Yards Number of Rushing Yards An array of the structure with 30 components is declared to store the data of football players. A function is provided to open the input file. A function skeleton is provided to read the data in the file “footballdata.txt” into the structure array. An Integer function is provided to search the structure array to find the index of a specific player. A function has been provided to using the index returned from the search, print all information for a player using the index returned from the search. A function has been provided to print all data for all players. A…arrow_forwardC++ Visual Studio 2019 Complete #7 Customer Accounts and #8 Search Function for Customer Accounts Program. Create the array with only 2 elements. 7.Customer Accounts Write a program that uses a structure to store the following data about a customer account: Name Address City, State, and ZIP Telephone Number Account Balance Date of Last Payment The program should use an array of at least 10 structures. It should let the user enter data into the array, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface. Input Validation: When the data for a new account is entered, be sure the user enters data for all the fields. No negative account balances should be entered. 8. Search Function for Customer Accounts Program Add a function to Programming Challenge 7 (Customer Accounts) that allows the user to search the structure array for a particular customer's account. It should accept part of the customer's name as an…arrow_forward. Complete the program to processes an array of structured data. Complete those portions indicated in the template. The program has defined a structure named Sale. The structure has the following fields: string itemName int quantity double unitPrice The main function call loadUserlnput which returns a pointer to the first Sale element in the dynamically allocated array of Sale elements and an integer for the number of Sale elements in the array. The main function then calls printData to show the sale items including the total of cach sale item and the total of the entire list. Function printData This is the function you need to complete as well as two other helper functions. In the function body, print the report heading. Then iterate through the array received through the parameters and print the data according to the required format. For the total of each item, call getltemTotal. At the end of the report, print the total of the entire sale items by calling getTotal. Test The Program…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning