C++ How to Program (10th Edition)
10th Edition
ISBN: 9780134448237
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 22, Problem 22.4E
Program Plan Intro
To Determine:
Definition for each of the following:
- Structure inventory, containing character array part name [30], integer part number, floating-point price, integer stock and integer reorder.
- A structure called address that contains character arrays street address [25], city [20], state [3] and zipcode [6].
- Structure student, containing arrays first name [15] and last name [15] and variable home address of type struct address from part (b).
- Structure test, containing 16 bit fields widths of 1 bit. The names of the bit fields are the letters a to p.
Expert Solution & Answer
Explanation of Solution
Explanation:
Defining Structures:
Structure is nothing but the collection of different variables of different types. First we need to define a structure in the program, for that we need to use the keyword struct and then the name of the structure. The name under which we want to combine different-different variables or different-different elements and between the curly braces whatever we write or whatever variables we declare will be considered as the members of the structure. All the members will be available under this one name of the structure. Declaring or defining the member of a structure is similar to the way we declare the variables.
- Here we are storing the information of Inventory, so the structure name will be Inventory and all the members are available under this one name Inventory.
- Here we are storing the information of Address, so the structure name will be Address and all the members are available under this one name Address.
- Here we are storing the information of Student, so the structure name will be Student and all the members are available under this one name Student.
- Here we are storing the information of Test, so the structure name will be Test and all the members are available under this one name Test.
structInventory { charpartName[30]; intpartNumber; floatprice; intstock; intrecorder; };
structAddress { charstreetAddress[25]; charcity[20]; charstate[3]; charzipCode[6]; };
structStudent { charfirstName[15]; charlastName[15]; struct { charstreetAddress[25]; charcity[20]; charstate[3]; charzipCode[6]; } homeAddress; };
structTest { boola:1, b:1, c:1, d:1, e:1, f:1, g:1, h:1, i:1, j:1, k:1, l:1, m:1, n:1, o:1, p:1; };
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
In C programming language
Question (Array of Structures)
a) Write a program that declares a structure student with the following data members;
Name (String)
RollNo(Integer)
CGPA(Float)
b) Create an array s1 of 5 elements in main function of type structure student
c) Initialize all the structures stored within array.
d) Print all array contents.
Provide the definition for each of the following structures and unions:
4) Structure student that contains arrays firstName[ 15 ] and lastName[ 15 ] and variable
Provide the definition for each of the following structures and unions:
3) A structure called address that contains character arrays streetAddress[ 25 ], city[ 20 ],state[ 3 ] and zipCode[ 6 ].
Chapter 22 Solutions
C++ How to Program (10th Edition)
Ch. 22 - Prob. 22.4ECh. 22 - Prob. 22.5ECh. 22 - (Shifting and Printing an Integer) Write a program...Ch. 22 - (Multiplication Via Bit Shifting) Left-shifting as...Ch. 22 - (Packing Characters into Unsigned Integers) The...Ch. 22 - (Unpacking Characters from Unsigned Integers)...Ch. 22 - Prob. 22.10ECh. 22 - Prob. 22.11ECh. 22 - (Determine the Value) The following program uses...Ch. 22 - Prob. 22.13E
Ch. 22 - Prob. 22.14ECh. 22 - (Converting Strings to Integers) Write program...Ch. 22 - Prob. 22.16ECh. 22 - (searching for Substrings) Write a program that...Ch. 22 - (Searching for Substrings) Write a program based...Ch. 22 - Prob. 22.19ECh. 22 - Prob. 22.20ECh. 22 - (ASCII Character Set) The chart in Appendix B...Ch. 22 - Prob. 22.22ECh. 22 - Prob. 22.23ECh. 22 - (Displaying Characters for Given ASCII Codes)...Ch. 22 - Prob. 22.25ECh. 22 - Prob. 22.26ECh. 22 - Prob. 22.27ECh. 22 - Prob. 22.28ECh. 22 - Prob. 22.29ECh. 22 - Prob. 22.30ECh. 22 - Prob. 22.31ECh. 22 - (Limericks) A limerick is a humorous five-line...Ch. 22 - Prob. 22.33ECh. 22 - Prob. 22.34ECh. 22 - Prob. 22.35ECh. 22 - Prob. 22.36ECh. 22 - Prob. 22.37ECh. 22 - Prob. 22.38ECh. 22 - Prob. 22.39ECh. 22 - Prob. 22.40ECh. 22 - Prob. 22.41ECh. 22 - (Word Processing) One important function in...Ch. 22 - (Printing Dates in Various Formats) Dates are...Ch. 22 - (Check Protection) Computers are frequently in...Ch. 22 - (Writing the Word Equivalent of a Check Amount)...Ch. 22 - (Morse Code) Perhaps the most famous of all coding...Ch. 22 - Prob. 22.47ECh. 22 - (Crossword Puzzle Generator) Most people have...Ch. 22 - (Spelling Checker) Many popular word-processing...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 3. Assume you have the following structure definition: struct parts { string name; int num; float price; int qInStock; }; a. Write a program that declares an array of the parts structure, size 10, name of your choice, and includes the following: Write a void function to request user input into each of the component members of the parts structure array. Be sure to include proper user prompts. Assume the entire structure array is filled. Write the prototype and the function definition. Call the function from main.Write a void function to output the information in the parts structure array. Write the prototype and the function definition. Call the function from main.arrow_forwardUse C++ codingNested Structures: Define a structure for Student containing information about name, roll number, address. The Address is itself another structure containing house no., street no., sector no., phase no., city name. Using arrays declare two addresses for the student: one address is for temporary address and second one is for permanent address. Declare one student structure variable and using pointer to this structure variable take input from the user to enter the information about the student.arrow_forwardC PROGRAMMING Instructions: Edit the code below to meet the criteria of the following steps: Step 1) Enter the lengths of the sides directly into the structure using a structure pointer and the "->" operator. Step 2) Create a new function, and calculate the perimeter and area of the triangle within it. Pass the triangle structure to the function by reference using the structure pointer. Step 3) In the main( ) function, print the perimeter and area directly from the triangle structure to the console. Use the structure pointer and "->" operator in the call to printf( ). __________________________________________________________________________________________ #include <stdio.h>#include <stdlib.h>#include <math.h> struct calculate{ float a, b, c, perimeter, area;}; int main(){ struct calculate tri; printf("Enter Side Lengths of a Triangle: \n"); scanf("%f\n", &tri.a); scanf("%f\n",…arrow_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_forwardC PROGRAMMING - Edit the Code Below to Use Pointers Instructions) Edit the code in order to make the user enter the lengths of the sides of the triangle directly into the structure using a structure pointer and the "->" operator. Then, in a function, calculate the perimeter and area of the triangle. Pass the triangle structure to the function by reference using the structure pointer. Lastly, in the main() function, print the perimeter and area directly from the triangle structure to the console. Use the structure pointer and "->" operator in the call to printf( ). ------------------------------------------------------------------------------------------------------------------------------------------------------ #include <stdio.h>#include <stdlib.h>#include <math.h> struct calculate{ float a, b, c, perimeter, area;}; int main(){ struct calculate tri; printf("Enter Side Lengths of a Triangle: \n"); scanf("%f\n", &tri.a);…arrow_forward/* Programming concept: structures Program should: be a C program, define a structure to store the year, month, day, and high temperature. write a function get_data that has a parameter that is a pointer to a struct and reads from the user into the struct pointed to by the parameter. write a function print_data that takes the struct pointer as a parameter and prints the data. in main, declare a struct, call the get_data function, call the print_data function. */ #include <stdio.h> int main(int argc, char *argv[]) { return 0;}arrow_forward
- DO YOUR OWN CODING 4) Implement this C program by defining a structure for each payment. The structureshould have at least three members for the interest, principle and balanceseparately. And store all the payments in a structure array (the max size of whichcould be 100). Name this C program as loanCalcStruct.c .arrow_forwardmodule 4: Differentiate between Writing Functions for Array and Writing Functions for Structures.arrow_forwardEncapsulation is the way to add functions in a user defined structure. a) True b) Falsearrow_forward
- typedef char string[50]; struct a Tag { int a; }; // 1. indicate the data type returned by function Exam() Exam(struct a Tag *ptr) { float b; double C[ 10 ]; string s; } // Access the members of the structure variable indirectly via ptr // You are REQUIRED to use the structure pointer operator; see comments numbered 2 to 5. // 2. input the value of member a scanf("%d", ); // 3. assign 3.1416 as the value of member b = 3.1416; // 4. print the value of the last element of array C. printf("%lf\n", |); // 5. copy "Hello" into string s strcpy( return ptr; , "Hello");arrow_forwardProvide the definition for each of the following structures and unions: 1) Structure inventory containing character array partName[ 30 ], integer partNumber,floating point price, integer stock and integer reorder.arrow_forwardComplete 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_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License