Concept explainers
Give a definition for the function with the following function declaration. The class BankAccount is defined in Display 10.5. (Hint: It’s easy if you use a member function.)
void doubleUpdate(BankAccount& theAccount); //Precondition: theAccount has previously been given a value //(that is, its member variables have been given values). //Postcondition: The account balance has been changed so that //two years' interest has been posted to the account. |
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Problem Solving with C++, Student Value Edition
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Starting Out with Python (4th Edition)
Starting Out with Python (3rd Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Computer Science: An Overview (12th Edition)
- Assume the definition of class foodType as given in Exercise 6. Answer the following questions? (1, 2, 3, 5, 6) Write the definition of the member function set so that private members are set according to the parameters. The values of the int and double instance variables must be nonnegative. Write the definition of the member function print that prints the values of the data members. Write the definitions of the member functions getName, getcalories, getFat, getSugar, getCarbohydrate, getPotassium to return the values of the instance variable. Write the definition of the default constructor of the class foodType so that the private member variables are initialized to 0, 0. 0, 0, 0. 0, 0. 0, respectively. Write the definition of the constructor with parameters of the class foodType so that the private member variables are initialized according to the parameters. The values of the int and double instance variables must be nonnegative. Write a C + + statement that prints the value of the object fruit 2. Write a C++ statement that declares an object my Fruit of type foodType, and initializes the member variables of myFruit to Apple, 52, 0. 2, 10,13.8, and 148.0, respectively.arrow_forwardWrite a program IN C++ to model a student class with roll number and name as the sensitive information. Initialize default values for the sensitive information using a default constructor, use a copy constructor to copy from another object, use a member function to take user input and update the name and roll number and display the same using another member function. b.Add constructor overloading to the above code and enable initialization of name, roll number via constructor arguments. NAME ROHI ROLLNO 18arrow_forwardWrite a program IN C++ to model a student class with roll number and name as the sensitive information. Initialize default values for the sensitive information using a default constructor, use a copy constructor to copy from another object, use a member function to take user input and update the name and roll number and display the same using another member function. b.Add constructor overloading to the above code and enable initialization of name, roll number via constructor arguments. NAME KOHLI ROLLNO 18arrow_forward
- - Implement the class “cylinder” with member variables radius and height, whichare private of type double. Define the global constant PI=3.1415 and use it incalculating the volume of the cylinder (PI*radius*radius*height).Implement in the class cylinder the following functions:a- A default constructor with default values of one.b- One constructor with two arguments. This constructor should check that thevariable is positive and does not exceed 20, otherwise the variable will beassigned its default value of one.c- A reader for each variable.d- A writer for each variable.e- A reader and a writer for diameter.f- A member function “volume” which calculates the volume of a cylinder.g- A member function “print” which prints the radius, diameter, and height of acylinder.h- A member function display_name() which displays “cylinder”.2- Write a program which declares an array of n cylinders (use n=5). Initialize thearray values by writing a loop which asks the user to input the radius and…arrow_forwardGiven the Class Definition for ClockType discussed extensively in class, write what would have to be added to the IMPLEMENTATION FILE for the Class ClockType to overload the “= =”, i.e., the comparison “equal-equal sign,” here: That is, write the FULL FUNCTION DEFINITION for THE FUNCTION associated with Class ClockType to overload the “= =” remembering the private members are: b) int hr; // that contains the hours int min; // that contains the minutes int sec; // that contains the secondsarrow_forwardA(n)_ is a class that only contains virtual functions that are pure virtual. Fill in the blanks with your answer to this question.arrow_forward
- Write a program in the C++ language to create a class Rectangle with two member integer variables length and breadth. Write the parameterized constructor for the class and also add a member function that displays the area of the rectangle in the output.arrow_forwardWrite the definitions of the member functions of the class calendarType (designed in Programming Exercise 9) to implement the operations of the class calendarType. Write a test program to print the calendar for either a particular month or a particular year. For example, the calendar for September 2019 is: (check the picture)This is exercise 9: Using the classes extDateType (Programming Exercise 8) and dayType (Chapter 10, Programming Exercise 5), design the class calendarType so that, given the month and the year, we can print the calendar for that month. To print a monthly calendar, you must know the first day of the month and the number of days in that month. Thus, you must store the first day of the month, which is of the form dayType, and the month and the year of the calendar. Clearly, the month and the year can be stored in an object of the form extDateType by setting the day component of the date to 1 and the month and year as specified by the user. Thus, the class…arrow_forwardWrite a class basicMaths and use constructor to pass a number. Create a function FindNumber takes one number as a parameter and Ñnds if it is positive or negatieve number. Create another class intermediateMaths with same functions and redeÑne the FindNumber functionality by Ñnding the number as even or odd number. Create another class advanceMaths with same functions and redeÑne the FindNumber functionality by Ñnd the number as prime number or composite number. Consider the following example code for the logic of prime number:arrow_forward
- Implement the Rectangle class as discussed this week. Use the class declaration below. Your job is to implement the functions. Implement the missing functions yourself. class Rectangle{ private: double width; double length; char *name; void initName(char *); public://constructorsRectangle();Rectangle(double, double, char*);//destructor ~Rectangle(); void setWidth(double); void setLength(double); void setWidth(char *); void setLength(char *); void setName(char *); double getWidth() const; double getLength() const; void printName() const { cout << name; }}; A few notes on the functions: initName(char *): this is a private member function. It should be the only function which dynamically allocates a char array to hold the name. setName(char *): this is a public member function which changes the name of the rectangle to a new name. It does not dynamically allocate memory, it only changes name. Demonstrate your class works…arrow_forwardcreat a c++ project that Consider the following definition of a class. class displayClass { public: void print(); ... private: int listLength; int *list; double salary; string name; } parta. Write the function prototype to overload the assignment operator for the class displayClass. part b. Write the definition of the function to overload the assignment operator for the class displayClass. partc. Write the function prototype to include the copy constructor for the class displayClass. partd. Write the definition of the copy constructor for the class displayClassarrow_forwardAnswer this in C++: In the Student.cpp file and Student.h file, build the Student class with the following specifications: Private data members string name - Initialized in default constructor to "Louie" double gpa - Initialized in default constructor to 1.0 Default constructor Public member functions SetName() - sets the student's name GetName() - returns the student's name SetGPA() - sets the student's GPA GetGPA() - returns the student's GPA Ex. If a new Student object is created, the default constructor sets name to "Louie" and gpa to 1. The output of GetName() and GetGPA() before and after calling SetName("Felix") and SetGPA(3.7) is: Louie/1 Felix/3.7 main.cpp #include <iostream> #include <vector> #include "Student.h" using namespace std; int main() { Student student = Student(); cout << student.GetName() << "/" << student.GetGPA() << endl; student.SetName("Felix"); student.SetGPA(3.7); cout <<…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning