Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 11, Problem 1PP
Program Plan Intro
Creation of program to construct class for a vector
Program Plan:
- Define a file “vectorDouble.h” to define properties of vector.
- Define a function prototype for constructor “VectorDouble()”.
- Define a function prototype for destructor “~VectorDouble()”.
- Define a function prototype for method “push_back()”.
- Define a function prototype for method “value_at()”.
- Define a function prototype for method “change_value_at()”.
- Define a function prototype for method “size()”.
- Define a function prototype for method “capacity()”.
- Define a function prototype for method “reserve()”.
- Define a function prototype for method “resize()”.
- Define a function prototype for method “operator<<()”.
- Define a function prototype for method “operator==()”.
- Define a function prototype for method “operator=()”.
- Define a function prototype for method “expandCapacity()”.
- Define a file “vectorDouble.cpp” to define properties of vector.
- Define a method for constructor “VectorDouble()” to create instance of vector.
- Define a method for destructor “~VectorDouble()” to destroy existing vector instances.
- Define a method “push_back()” to push value into array.
- Define a method “value_at()” to return value of element.
- Define a method “change_value_at()” to change value of element.
- Define a method “size()” to compute size of array.
- Define a method “capacity()” to return maximum count possible.
- Define a method “reserve()” to create new array and reserve space.
- Define a method “resize()” to resize the existing array.
- Define a method “operator<<()” to create an overloaded operator.
- Define a method “operator==()” to create an overloaded operator.
- Define a method “operator=()” to create an overloaded operator.
- Define a method “expandCapacity()” to expand capacity of array.
- Define a file “Source.cpp” to call member functions and methods.
- Create instance for vector class.
- Insert values into array.
- Call method “push_back()” to push value into array.
- Call method “value_at()” to return value of element.
- Call method “change_value_at()” to change value of element.
- Call method “size()” to compute size of array.
- Call method “capacity()” to return maximum count possible.
- Call method “reserve()” to create new array and reserve space.
- Call method “resize()” to resize the existing array.
- Call method “operator<<()” to create an overloaded operator.
- Call method “operator==()” to create an overloaded operator.
- Call method “operator=()” to create an overloaded operator.
- Call method “expandCapacity()” to expand capacity of array.
- Display resultant values.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write in C++ a class Restaurants to manage a vector of Restaurant objects. The class Restaurants should have:
• A private vector to store Restaurant objects
• A public add method to add a Restaurant to the Restaurants
• A public average_max_rating method that returns the average of max ratings of the
restaurants.
• A public get_max method that returns the Restaurant that has highest max rating.
One problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector . This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings.
The class should have the following
A private member variable called dynamicArray that references a dynamic array of type string.
A private member variable called size that holds the number of entries in the array.
A default constructor that sets the dynamic array to NULL and sets size to 0.
A function that returns size .
A function named addEntry that takes a string as input. The function should create a new dynamic array one element larger than dynamicArray , copy all elements from dynamicArray into the new array, add the new string onto the end of the new array, increment size, delete the old dynamicArray ,…
Design a struct personalinfo with components id, and name of type string.
Design a class student with private data member's person (struct variable of type personalInfo),
number Of Courses (of type integer), average (of type float), and marks[] an array of student's marks of
type integer. The class also has the member functions ser( ), getPerson(), print(), findAverage(),
getAverage(), and a parameterized constructor with default value 1 for the number of courses.
Implement the member functions of the class student.
The member function findAverage() is used to calculate the average mark for each student.
I
Write a driver that does the following:
Declares the array section[ ] of objects of student type.
Reads the number of students.
Reads information for each student from the file student.txt.
Calls the user-defined function
int maxAverageIndex(int, student [])
Prints the id and name of the student with the maximum average.
Student.txt:
4
1463491 Ali
72 65 81 85
1370005 Yousef 5 91 82…
Chapter 11 Solutions
Problem Solving with C++ (10th Edition)
Ch. 11.1 - Write a function definition for a function called...Ch. 11.1 - What is the difference between a friend function...Ch. 11.1 - Suppose you wish to add a friend function to the...Ch. 11.1 - Prob. 4STECh. 11.1 - Notice the member function output in the class...Ch. 11.1 - Notice the definition of the member function input...Ch. 11.1 - The Pitfall section entitled Leading Zeros in...Ch. 11.1 - Give the complete definition of the member...Ch. 11.1 - Why would it be incorrect to add the modifier...Ch. 11.1 - What are the differences and the similarities...
Ch. 11.1 - Given the following definitions: const int x = 17;...Ch. 11.2 - What is the difference between a (binary) operator...Ch. 11.2 - Prob. 13STECh. 11.2 - Suppose you wish to overload the operator = so...Ch. 11.2 - Prob. 15STECh. 11.2 - Give the definition for the constructor discussed...Ch. 11.2 - Here is a definition of a class called Pairs....Ch. 11.2 - Following is the definition for a class called...Ch. 11.3 - Give a type definition for a structure called...Ch. 11.3 - Write a program that reads in five amounts of...Ch. 11.3 - Change the class TemperatureList given in Display...Ch. 11.3 - Prob. 22STECh. 11.3 - If a class is named MyClass and it has a...Ch. 11.4 - Prob. 24STECh. 11.4 - The following is the first line of the copy...Ch. 11.4 - Answer these questions about destructors. a. What...Ch. 11.4 - a. Explain carefully why no overloaded assignment...Ch. 11 - Modify the definition of the class Money shown in...Ch. 11 - Self-Test Exercise 17 asked you to overload the...Ch. 11 - Self-Test Exercise 18 asked you to overload the...Ch. 11 - Prob. 1PPCh. 11 - Define a class for rational numbers. A rational...Ch. 11 - Define a class for complex numbers. A complex...Ch. 11 - Enhance the definition of the class StringVar...Ch. 11 - Define a class called List that can hold a list of...Ch. 11 - Define a class called StringSet that will be used...Ch. 11 - This programming project requires you to complete...Ch. 11 - Redo Programming Project 6 from Chapter 9 (or do...Ch. 11 - Solution to Programming Project 11.12 To combat...Ch. 11 - Repeat Programming Project 11 from Chapter 10 but...Ch. 11 - Do Programming Project 19 from Chapter 8 except...
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
- In c++, Consider a class BankAccount that has Two attributes i.e. accountID and balance and A function named balanceInquiry() to get information about the current amount in the account Derive two classes from the BankAccount class i.e. CurrentAccount and the SavingsAccount. Both classes (CurrentAccount and SavingsAccount) inherit all attributes/behaviors from the BankAccount class. In addition, followings are required to be the part of both classes Appropriate constructors to initialize data fields of base class A function named amountWithdrawn(amount) to withdraw certain amount while taken into account the following conditionso While withdrawing from current account, the minimum balance should not decrease Rs. 5000o While withdrawing from savings account, the minimum balance should not decrease Rs. 10,000 amountDeposit(amount) to deposit amount in the account In the main() function, create instances of derived classes (i.e. CurrentAccount and SavingsAccount) and invoke their…arrow_forwardc++ Implement a MyInt class. An object in the MyInt class must be able to hold a single dynamically allocated integer. MyInt should have the following members: A member variable ptr of type int *.A parameterized constructor that takes nums of type int as input parameters.A destructor.A superimposed assignment operator (). The copy must be deep.A function set that sets the value of the number.A function get that returns the value of the number.The members must be encapsulated in accordance with the convention. Memory leaks must be avoided. To test your class, create objects and call functions according to the comments below. All tests must be validated. Input Expected output5 11 27 5 11 271 2 3 1 2 319 21 30 19 21 30arrow_forwardCreate parent class Shapes with protected parameters width and height and function printarea() and a virtual function cal_area(). Create two sub classes Rectangle and Sqaure. In main() create 2 pointers of Shapes and assign Rectangle and Square to it. Call printarea function with the pointers. Note: Use C++ language with well explaination. After performing this program. Implement this program using an abstract class.arrow_forward
- Solve the problem in C++ (Extend MyPoint) In Programming Exercise 9.4, the MyPoint class was created to model a point in a two-dimensional plane. The MyPoint class has the properties x and y that represent x- and y-coordinates, two getter functions for x and y, and the function for returning the distance between two points. Create a class named ThreeDPoint to model a point in a three-dimensional space. Let ThreeDPoint be derived from MyPoint with the following additional features: - A data field named z that represents the z-coordinate.- A no-arg constructor that constructs a point with coordinates (0, 0, 0).- A constructor that constructs a point with three specified coordinates.- A constant getter function that returns the z value.- A constant distance(const MyPoint&) function to return the distance between this point and the other point in the three-dimensional space. Draw the UML diagram for the classes involved. Implement the classes. Write a test program that creates two…arrow_forwardWrite a complete C++ program that implements the followings: A. A class called Books. The class Books private data members should include: 1. Title: array of 30 char variables. 2. ISBN: pointer to an int variable. 3. Orders: array of 7 double variables. The class Books also should include the following public member functions: 4. For each data member: Title, ISBN, and Orders provide a parametrized Set function to store the received parameters for each one of them. 5. For each data member: Title, ISBN, and Orders provide an empty Get function to return the value for each one of them. 6. Provide the parametrized function TotalCost that returns the Orders summation multiplied by Price. Price a double parameter received by this function. B. The main function should include: 1. Definition for the object OBJ from the class Books. 2. Calling statements for the Set functions of the object OBJ. Prompt to the user to enter arguments to be passed for the functions. 3. Print the information for…arrow_forwardThis is in c++ The base class Pet has private data members petName, and petAge. The derived class Dog extends the Pet class and includes a private data member for dogBreed. Complete main() to: create a generic pet and print information using PrintInfo(). create a Dog pet, use PrintInfo() to print information, and add a statement to print the dog's breed using the GetBreed() function. main.cpp #include <iostream> #include<string> #include "Dog.h" using namespace std; int main() { string petName, dogName, dogBreed; int petAge, dogAge; Pet myPet; Dog myDog; getline(cin, petName); cin >> petAge; cin.ignore(); getline(cin, dogName); cin >> dogAge; cin.ignore(); getline(cin, dogBreed); // TODO: Create generic pet (using petName, petAge) and then call PrintInfo // TODO: Create dog pet (using dogName, dogAge, dogBreed) and then call PrintInfo // TODO: Use GetBreed(), to output the breed of the dog } Dog.cpp #include "Dog.h" #include…arrow_forward
- Create a class employee with the data members,name,id and salary as private data member . Create array of objects for four employee.compare their salary using operator overloading,and display the records of the student who is getting less salary. By c++ language.arrow_forwardWrite a program in C++, that creates a class Rock with a default constructor, a copy-constructor, an assignment operator, and a destructor, all of which announce to cout that they’ve been called. In main( ), create a vector<Rock> (that is, hold Rock objects by value) and add some Rocks. Run the program and explain the output you get. Note whether the destructors are called for the Rock objects in the vector. Now repeat the exercise with a vector<Rock*>. Is it possible to create a vector<Rock&>?arrow_forwardc++ Declare an Animal class that has the attributes of Name, Genus, and Weight. Declare four (4) specific animal classes that inherit attributes from the Animal class. In the lab we built two, Duck and Butterfly. Implement show() and speak() methods for each subclass. These methods will also be virtual classes in Animal and will allow the use of an array of Animal* in the main(). Your program should ask the user for the number of animals they would like in there zoo. Allow the user to select each animal from the animal subclasses you have implemented. Store the selections in an array of Animal*. After the user has selected all the animals, step thru the array and have each animal show() and speak() in a sort of parade of selected animals. I'm having a problem with the error message and why it won't display to ascii art and have the user input --- This is my code so far --- /* * File: Zoo.cpp * Author: * Course: CS I * Assignment: What's In Your Zoo? * Due date: 11/10/21 * *…arrow_forward
- Create a class Employee with following data members, name, id, and salary as private datamember. Create array of objects for four employees, compare their salary using operatoroverloading, and display the records of the student who is getting less salary. by c++arrow_forwardWrite a simple C++ code I am a beginner. Subject: Object oriented programming Write a program that has an abstract base class. This class should have four member data variables and a pure virtual function. It should also have a method for setting the data variables. Derive a class from Base class and override a method in the base class. Write a main function that creates an object of derived class and sets the variables. Also write a top-level function that will take a parameter of type base class and return the value of the appropriate (override) function.arrow_forwardTHIS QUESTION IS RELATED TO SUBJECT OBJECT ORIENTED PROGRAMMING IN C++ . SOLVE this question in dev c++. please send it in 30 minutes and solve step by step. THANKS Q#5 Start with the safearay class from the ARROVER3 program in Chapter 8 of Object Orient programming by Rober Lafore. Make this class into a template, so the safe array can store any kind of data. Include following member functions in Safe array class. The minimum function finds the minimum value in array. The maximum function find the maximum value in array. The average function find average of all the elements of an array. The total function finds the running total of all elements of an array. In main(), create safe arrays of at least two different types int and double and store some data in them. Then display minimum, maximum, average and total of array elements. Note: use subscript ([]) operator in sasfearay class.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education