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
C PROGRAMMING (compiler: code blocks)
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.
Use 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.
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
- C programmingarrow_forward3. 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_forwardDO 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_forward
- C 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_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
- 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_forwardEncapsulation is the way to add functions in a user defined structure. a) True b) Falsearrow_forwardC++arrow_forward
- Q5) Write C++ program to create a function to read and find the summation of array values. The array represents the prameter of the function and contains 14 values, also the values of the array can be any numeric data type.arrow_forward2. Structure is another user defined data type available in C that allows combination of data items from different datatype and usually used to represent a record. a) Define a structure data type named BMI_ Data that consists of five data members (or member variables), which are character array variable named Name which can store maximum 50 characters, integer variable named Age and three floating point datatype named Weight, Height and BMI. b) Write a C programming statement to declare two struct BMI_Data variable, named erson1 and Person2.arrow_forwardProgramming: Simple Arrays Assignment Instructions Overview You will use the enumerated type and a switch to calculate the weight someone would have on another planet. Instructions Use a functional decomposition to write a C++ program that asks the user to enter his or her weight and the name of a planet. Use an enumerated type called planetType to represent the planets and use a switch statement that takes as its condition a planetType variable. The program, via the switch statement, then outputs to the screen how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet. Your program must have the following functions in it: GetUserInput() ConvertInputToPlanetType() OutputWeight() (your switch statement must be in OutputWeight()). Determine what each function’s parameters and return types should be. The program will output an error message if the user does not type a correct planet…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