STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 8.13, Problem 8.36CP
Program Plan Intro
Array of structures:
In C++, it is possible to create an array of structure. It is used to store a group of records contains multiple data members of various data type. A single array of structure can replace many arrays of regular type variable.
- Array of structures can be defined like normal array.
The structure array is declared through the following format:
struct_name variable[size];
Consider the following array definition:
//Declaration of structure array
Car values[5];
- In the above example, “Car” represents the structure type of the array, “values[]” is the array name, and the number inside the brackets is the size declaratory of the array.
Subscript of an array:
In C++, array elements can be accessed using a subscript. In an array, each element assigned with the unique number, which is specified inside the brackets, is referred to as a subscript.
- By default, structure members are defined as public. Hence structure members can be accessed by place the dot operator (.) and member name after the array subscript.
Example:
//Assign the value for model member of values[2].
values[2].model= "New"
- In above statement, the value “New” is assigned in the third element ofthe values array for model member.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Project 5 - Magic Squares
Objectives
The objective of this project is to have students practice with two-dimensional arrays and loops.
Specifications
In this project, you will write code to determine if a two-dimensional array of ints is a Magic Square. For a two-
dimensional array of ints to be a Magic Square all of the following must be true:
1. The array must be square - in other words, the lengths of all rows and all columns must be the same.
2. The array must contain all integers from 1 to n*n, where n is the length of the rows and columns.
3. The sum of the numbers in each diagonal, each row, and each column must be the same.
You have been given two classes:
• MagicSquareTest.java - Contains JUnit test cases for the MagicSquare class. Your code must pass all these tests.
• MagicSquare.java - contains static methods to determine if a two-dimensional array of ints is a Magic Square:
o isMagicSquare() - returns true if a two-dimensional array of ints meets all the criteria to be a…
You can copy all elements of one array into one another with an assignment statement.
True or False
CASE STUDY#:Grade Register
Write a grade register program to keep and process the grades of students. The program contain a class called GradeRegister. This class has two data members known as CourseName and an array of integer called Grades. The array Grades keep the grades of students of the same course. GradeRegister class have three methods as GetHighestGrade(), GetLowestGrade() and GetAverageGrade().The method GetHighestGrade return the maximum grade as integer from the array Grades and GetLowestGrade return the minimum grade value as integer from the array Grades. The GetAverageGrade method will return the average of grades from Grades array as float value. The parameterized constructor inside GradeRegister class will take two parameters to initialize the two data members of same class as mentioned before. Write a driver class GradeRegisterDriver to declare and initialize an integer array for grades and pass through the GradeRegister class constructor along with the course name.…
Chapter 8 Solutions
STARTING OUT WITH C++ MPL
Ch. 8.3 - Define the following arrays: A) empNum, a 100...Ch. 8.3 - Prob. 8.2CPCh. 8.3 - Prob. 8.3CPCh. 8.3 - Assume a program includes the following two...Ch. 8.3 - What is array bounds checking? Does C++ perform...Ch. 8.3 - What is the output of the following code? int...Ch. 8.3 - Complete the following program skeleton so it will...Ch. 8.7 - Define the following arrays: A) ages, a 10-element...Ch. 8.7 - Indicate if each of the following array...Ch. 8.7 - Prob. 8.10CP
Ch. 8.7 - Given the following array definition: int values...Ch. 8.7 - Prob. 8.12CPCh. 8.7 - Prob. 8.13CPCh. 8.7 - What is the output of the following code? const...Ch. 8.9 - Write a typedef statement that makes the name...Ch. 8.9 - Prob. 8.16CPCh. 8.9 - What is the output of the following program...Ch. 8.9 - The following program segments, when completed,...Ch. 8.11 - Prob. 8.19CPCh. 8.11 - Prob. 8.20CPCh. 8.11 - Prob. 8.21CPCh. 8.11 - Prob. 8.22CPCh. 8.11 - Prob. 8.23CPCh. 8.11 - Fill in the empty table below so it shows the...Ch. 8.11 - Write a function called displayArray7. The...Ch. 8.11 - Prob. 8.26CPCh. 8.12 - Prob. 8.27CPCh. 8.12 - Write definition statements for the following...Ch. 8.12 - Define gators to be an empty vector of ints and...Ch. 8.13 - True or false: The default constructor is the only...Ch. 8.13 - True or false: All elements in an array of objects...Ch. 8.13 - What will the following program display on the...Ch. 8.13 - Complete the following program so that it defines...Ch. 8.13 - Add two constructors to the Product structure...Ch. 8.13 - Prob. 8.35CPCh. 8.13 - Prob. 8.36CPCh. 8.13 - Prob. 8.37CPCh. 8.13 - Write the definition for an array of five Product...Ch. 8.13 - Write a structure declaration called Measurement...Ch. 8.13 - Write a structure declaration called Destination ,...Ch. 8.13 - Define an array of 20 Destination structures (see...Ch. 8 - The ________ indicates the number of elements, or...Ch. 8 - The size declarator must be a(n) _______ with a...Ch. 8 - Prob. 3RQECh. 8 - Prob. 4RQECh. 8 - The number inside the brackets of an array...Ch. 8 - C++ has no array ________ checking, which means...Ch. 8 - Prob. 7RQECh. 8 - If a numeric array is partially initialized, the...Ch. 8 - If the size declarator of an array definition is...Ch. 8 - Prob. 10RQECh. 8 - Prob. 11RQECh. 8 - Prob. 12RQECh. 8 - Arrays are never passed to functions by _______...Ch. 8 - To pass an array to a function, pass the ________...Ch. 8 - A(n) ________ array is like several arrays of the...Ch. 8 - Its best to think of a two -dimensional array as...Ch. 8 - Prob. 17RQECh. 8 - Prob. 18RQECh. 8 - When a two -dimensional array is passed to a...Ch. 8 - When you pass the name of an array as an argument...Ch. 8 - Look at the following array definition. int values...Ch. 8 - Given the following array definition: int values...Ch. 8 - Prob. 23RQECh. 8 - Assume that array1 and array2 are both 25-element...Ch. 8 - Prob. 25RQECh. 8 - How do you establish a parallel relationship...Ch. 8 - Look at the following array definition. double...Ch. 8 - Prob. 28RQECh. 8 - Prob. 29RQECh. 8 - Prob. 30RQECh. 8 - Prob. 31RQECh. 8 - The following code totals the values in each of...Ch. 8 - Prob. 33RQECh. 8 - Prob. 34RQECh. 8 - In a program you need to store the identification...Ch. 8 - Prob. 36RQECh. 8 - Prob. 37RQECh. 8 - Prob. 38RQECh. 8 - Each of the following functions contains errors....Ch. 8 - Soft Skills Diagrams are an important means of...Ch. 8 - Perfect Scores 1. Write a modular program that...Ch. 8 - Larger Than n Create a program with a function...Ch. 8 - Roman Numeral Converter Write a program that...Ch. 8 - Chips and Salsa Write a program that lets a maker...Ch. 8 - Monkey Business A local zoo wants to keep track of...Ch. 8 - Rain or Shine An amateur meteorologist wants to...Ch. 8 - Lottery Write a program that simulates a lottery....Ch. 8 - Rainfall Statistics Write a modular program that...Ch. 8 - Lo Shu Magic Square The Lo Shu Magic Square is a...Ch. 8 - Baseball Champions This challenge uses two files...Ch. 8 - Chips and Salsa Version 2 Revise Programming...Ch. 8 - Stats Class and Rainfall Statistics Create a Stats...Ch. 8 - Stats Class and Track Statistics Write a client...Ch. 8 - Prob. 14PCCh. 8 - Drivers License Exam The State Department of Motor...Ch. 8 - Array of Payro11 Objects Design a PayRoll class...Ch. 8 - Drink Machine Simulator Create a class that...Ch. 8 - Bin Manager Class Design and write an object...Ch. 8 - Tic-Tac-Toe Game Write a modular program that...Ch. 8 - Theater Ticket Sales Create a TicketManager class...
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
- QUESTIONS- 1. Create and array of objects named movies . Each of the objects in the array will represent a movie.Each object should have properties for:movie titlerelease yearrating (your rating 1 - 10)genres (an array of genres. eg ["Drama", "Mystery", "Sci-Fi", "Western"] )The array should contain at least 5 of movies you have seen (choose your own movies)You do not need to use JSON to create this arrayYou can use IMDB if you need help finding the info for your movie2. Now that digital format is taking over, we would like to add a property to each object for the format (“film” or“digital”). The property will be called format . Assuming that all movies in our data set where shot on film, use.forEach() to add the property and set a value of “film” for each movie.3. Use the .map() method to create an array of movie titles from our initial data set named movieTitles .4. Use the .reduce() method to find the highest and lowest rated movies in the data set. Store these objects invariables…arrow_forward(Electrical eng.) Write a program that declares three one-dimensional arrays named volts, current, and resistance. Each array should be declared in main() and be capable of holding 10 double-precision numbers. The numbers to store in current are 10.62, 14.89, 13.21, 16.55, 18.62, 9.47, 6.58, 18.32, 12.15, and 3.98. The numbers to store in resistance are 4, 8.5, 6, 7.35, 9, 15.3, 3, 5.4, 2.9, and 4.8. Your program should pass these three arrays to a function named calc_volts(), which should calculate elements in the volts array as the product of the corresponding elements in the current and resistance arrays (for example ,volts[1]=current[1]resistance[1]). After calc_volts() has passed values to the volts array, the values in the array should be displayed from inside main().arrow_forwardTOPIC: Passing Array to a Method and Returning Create a program that will determine the Second Largest number and the Second Smallest Number in an array Display the second largest and second smallest.arrow_forward
- Create a struct called Booking that consists of a 3 digit flight number (e.g. 234), type of seat (E or B), the price of a seat in economic class and the number of seats booked. Declare an array to store at least 30 Booking structs.arrow_forwardPseudocode for the student grade calculator program, please Create a program to enter grades and calculate averages and letter grades. Need a class which will contain: Student Name Student Id Student Grades (an array of 3 grades) A constructor that clears the student data (use -1 for unset grades) Get functions for items a, b, and c, average, and letter grade Set functions for items a, n, and c Note that the get and set functions for Student grades need an argument for the grade index. Need another class which will contain: An Array of Students (1 above) A count of number of students in use You need to create a menu interface that allows you to: Add new students Enter test grades Display all the students with their names, ids, test grades, average, and letter grade Exit the program Add comments and use proper indentation. Nice Features: I would like that system to accept a student with no grades, then later add one or more grades, and when all grades are entered, calculate the…arrow_forwardAn array's index type may be any form of data. Do you think this is true or not?arrow_forward
- C# Question Write a statement that declares an array of integers called lotteryPicks and assigns it to the value returned from calling a method named FillArray. The method takes a 3 value parameters, a string called prompt and 2 integers called low and high. Use the following literal values, “lottery numbers”, 1 and 69 as actual parameters in the callarrow_forwardWrite a program that shows Game sales. The program should use a structure to store the following data about the Game sale: Game company Type of Game (Action, Adventure, Sports etc.) Year of Sale Sale Price The program should use an array of at least 3 structures (3 variables of the same structure). It should let the user enter data into the array, change the contents of any element and display the data stored in the array. The program should have a menu driven interface. Input Validation: When the data for a new game sale is entered, be sure the user enters data for all the fields. No negative amounts should be entered for a “Sale Price” of the Game An example: You will use 1 structure only and then manipulate that for working with the information. The program should use an array of at least 3 structures (3 variables of the same structure). An example of the structure:struct Game{string name;string type;int year;double price;}; So far I have written that ...arrow_forwardWrite a statement that declares a class-level two-dimensional array named intOrders. The array should contain five rows and three columns.arrow_forward
- Code Should Be in Java: use loops, if statements, arrays, scanner etc Write an application that stores at least five different college courses (such as CIS101), the time it first meets in the week (such as Mon 9 am), and the instructor (such as Johnson) in a two-dimensional array. Allow the user to enter a course name and display the corresponding time and instructor. If the course exists twice, display details for both sessions. If the course does not exist, display an error message. Save the file as TimesAndInstructors.javaarrow_forwardWhat is sent into the parameter variable when an array is supplied as an argument?arrow_forwardCreate a struct called Booking that consists of a 3 digit flight number (e.g. 234), type of seat (E or B), the priceof a seat in economic class and the number of seats booked.Declare an array to store at least 30 Booking structs. The user must be able to enter the information for a number of bookings from the keyboard. Ask whether abooking must be made (Y or N). If a booking must be made, a random 3 digit flight number must be generated.The user must be asked to enter the type of seat, the price per seat and the number of seats to book. Example of input: Make a booking (Y or N): Y Type of seat (E or B): e Price per seat : 1200 Number of seats: 2 Make another booking (Y or N): y Type of seat (E or B): b Price per seat : 3400 Number of seats: 2 Make another booking (Y or N): y Type of seat (E or B): e Price per seat : 1400 Number of seats: 3 Make another booking (Y or N): y Type of seat (E or B): e Price per seat : 1300 Number of seats: 2 Make another booking (Y or N): y Type of…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr