Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 8, Problem 33RQE
Program Plan Intro
Structure array:
The structure needs an array if the items need to be grouped together.
- Array is a “derived” data type and it contains similar elements.
- The array index starts with 0.
- If the size of the array is 4, then the index values are “0”, “1”, “2”, and “3”.
Syntax:
struct_name array_name[size];
Example:
Book name[20];
Explanation:
“Book” is a structure name, “name” is an array name, and the value “20” is the “size” of an array.
Algorithm to define an array of structure to hold 12 records about city population and read the data from the specified file “pop.dat” and store it in structure members.
- Define the structure Population.
- Declare the structure variables such as city name and its population.
- Declare an array of structure cntry to hold 12 records.
- Define the main function
- Declare a file stream object.
- Open the file “pop.dat” using the object.
- Using for loop,
- Read city name and its population from the file and store it in structure members.
- Close the file.
- Read city name and its population from the file and store it in structure members.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In a program you need to store the names and populations of 12 countries. Create an appropriate array to store this information and then write the code needed to read the information into the array from a file named pop.dat.
For this programming exercise you will use the text file named “USPopulation.txt” that is located on Blackboard in the same location as these instructions. The file contains the midyear population of the United States, in thousands, during the years 1950 through 2000. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth. Write a program that reads the contents of the file into an array. The program should display the following information: • The average annual change in population during the time period. • The year with the greatest increase in population during the time period. • The year with the smallest increase in population during the time period.
Using C# in Microsoft Visual Studio create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. (The correct answers are provided in the screenshot.) the program should store these correct answers in an array. The program should read the student’s answers for each of the 20 questions from a text file and store the answers in another array. (Create your own text file to test the application.) After the student’s answers have been read from the file, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions.
Chapter 8 Solutions
Starting Out with C++: Early Objects (9th Edition)
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
Similar questions
- FYI: Please write the code in Pseudocode (no programming language please) 1. Write pseudocode to load a single array with data. Then search that array for a match. Here are the specifics. You do NOT have to write the entire program. Load the array with data from a file named customerNumbers Ask the user to enter their customer number Search the array for the customer number If you find a match output FOUND If there is no match output NOT FOUNDarrow_forwardThe local driver’s license office has asked you to create an application that grades the written portion of the driver’s license exam. The exam has 20 multiple-choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C B D A Your program should store these correct answers in an array. The program should read the student’s answers for each of the 20 questions from a text file and store the answers in another array. (Create your own text file to test the application.) After the student’s answers have been read from the file, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions. Need Visual Studio Code (C Language )arrow_forwardThe array fileSize contains the sizes of all files stored in a folder. Fill in the blank with a line of code that outputs the fifth array element from the beginning of the array.arrow_forward
- Please written by computer sourcearrow_forwardIn a program you need to store the identification numbers of 10 employees (as ints) and their weekly gross pay (as doubles). A) Define two arrays that may be used in parallel to store the 10 employee identification numbers and 10 weekly gross pay amounts.B) Write a loop that uses these arrays to print each employee’s identification number and weekly gross pay.arrow_forwardDeclare a variable named num with an initial value of 0. Create a while loop that will print "Keep going" as long as the value of num is less than 5. Use window.alert() for displaying the output. Create a function named showProd that returns the product of n1 and n2. Using the new keyword, create an array named info with three (3) values: your first name, your nickname, and your last name.arrow_forward
- Extend the program below so that after closing the files, program asks the user to enter a name. The program should store this input as a string, and then search the name array for the ‘search name’ just entered by the user. If the search name is found in the name array, the program will print the name, age and wage corresponding to the search name to the screen. If the search name is not found in the name array, program prints “Name not found” to the screen. The search would need to use string comparison functions. (b) #include<stdio.h>#include<stdlib.h> char c;char name[10][50];int roll[10];float marks[10]; int main (int argc, char **argv) { FILE* f; if (argc != 2) { printf("No filename in the argument"); return 1; } f = fopen(argv[1], "r"); if (f == NULL) { printf("The file cannot be opened successfully: %s\n",argv[1]); return 1; } printf("The file has been opened successfully\n\n"); int lines = 0;…arrow_forwardCalculate average test score: Write a program that reads 10 test scores in an array named testScores. Then pass this array to a function to calculate the average test scores, return the average to main function and display it. Input Validation: The test scores should be between 0 and 100 (inclusive). Add comments and version control.arrow_forwardThis program needs 3 parts Read in this attached inputFile.txt (75 50 60 80 90) from a file into your Grade array. Use a bubble sort to sort the array (Print to console each pass of the array until the array is sorted.) Write out to console the low score the high score and the average scorearrow_forward
- AskForNumbers Declare an integer array locally with the size of 200. Create a program that asks the user how many numbers the have. Use your getChoice() function from before. Make sure it does not exceed 200 as the locally declared array has the size of 200 Use a for loop and ask the user to enter each value that must be stored in the array Use a second loop to display each number, and also determine the average of all values in the array After the for loop, display the average of all numbers. This program will let you enter a list of numbers into an array. It will then display all of the numbers, and finally display the average of all numbers. How many numbers would you like to enter?5 Please enter a number: 22 Please enter a number: 33 Please enter a number:44 Please enter a number: 55 Please enter a number: 66 lumber 1 is 22 lumber 2 is 33 lumber 3 is 44 lumber 4 is 55 lumber 5 is 66 The average is 44arrow_forwardi need the answer quicklyarrow_forwardA file named history.txt contains unknown number of car records (maximum no. of records is 50). Each line in the file consists of car model (string), mileage (integer), and number of accidents (integer). Write a program that reads the data from the file into 3 parallel arrays. Your program should display the following: • Display the number of cars found. Display car information (car model and number of accidents) for all cars in file. • Display the average mileage of all cars Display the car model with the highest number of accidents.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 PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Programming 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 Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
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,