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
MYPROGRAMMINGLAB WITH PEARSON ETEXT
- can u solve this questionarrow_forward1. Unsigned Integers If we have an n-digit unsigned numeral dn-1d n-2...do in radix (or base) r, then the value of that numeral is n−1 r² di Σi=0 which is basically saying that instead of a 10's or 100's place we have an r's or r²'s place. For binary, decimal, and hex r equals 2, 10, and 16, respectively. Just a reminder that in order to write down a large number, we typically use the IEC or SI prefixing system: IEC: Ki = 210, Mi = 220, Gi = 230, Ti = 240, Pi = 250, Ei = 260, Zi = 270, Yi = 280; SI: K=103, M = 106, G = 109, T = 10¹², P = 1015, E = 10¹8, Z = 1021, Y = 1024. 1.1 Conversions a. (15 pts) Write the following using IEC prefixes: 213, 223, 251, 272, 226, 244 21323 Ki8 Ki 223 23 Mi 8 Mi b. (15 pts) Write the following using SI prefixes: 107, 10¹7, 10¹¹, 1022, 1026, 1015 107 10¹ M = 10 M = 1017102 P = 100 P c. (10 pts) Write the following with powers of 10: 7 K, 100 E, 21 G 7 K = 7*10³arrow_forwardanswer shoul avoid using AI and should be basic and please explainarrow_forward
- Node A is connected to node B by a 2000km fiber link having a bandwidth of 100Mbps. What is the total latency time (transmit + propagation) required to transmit a 4000 byte file using packets that include 1000 Bytes of data plus 40 Bytes of header.arrow_forwardanswer should avoid using AI and should be basic and explain pleasearrow_forwardasnwer should avoid using AIarrow_forward
- answer should avoid using AI (such as ChatGPT), do not any answer directly copied from AI would and explain codearrow_forwardWrite a c++ program that will count from 1 to 10 by 1. The default output should be: 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10 There should be only a newline after the last number. Each number except the last should be followed by a comma and a space. To make your program more functional, you should parse command line arguments and change behavior based on their values. Argument Parameter Action -f, --first yes, an integer Change place you start counting -l, --last yes, an integer Change place you end counting -s, --skip optional, an integer, 1 if not specified Change the amount you add to the counter each iteration -h, —help none Print a help message including these instructions. -j, --joke none Tell a number based joke. So, if your program is called counter, counter -f 10 --last 4 --skip 2 should produce 10, 8, 6, 4 Please use the last supplied argument. If your code is called counter, counter -f 4 -f 5 -f 6 should count from 6. You should…arrow_forwardshow workarrow_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 LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning