I am Thanasis F. I am an Online C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Harvard University. I have been helping students with their homework for the past 6 years. I solve homework related to Online C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Online C++ Homework.
I am Stuart M. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from, the University of Greenwich, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Irene M. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from from California, USA. I have been helping students with their homework for the past 10 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Stuart M. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from, the University of Greenwich, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Irene M. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from from California, USA. I have been helping students with their homework for the past 10 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
While writing program in any language, you need to use various variables to s...bhargavi804095
While writing program in any language, you need to use various variables to store various information. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
Static Keyword Static is a keyword in C++ used to give special chara.pdfKUNALHARCHANDANI1
Static Keyword Static is a keyword in C++ used to give special characteristics to an element.
Static elements are allocated storage only once in a program lifetime in static storage area. And
they have a scope till the program lifetime. Static Keyword can be used with following, Static
variable in functions Static Class Objects Static member Variable in class Static Methods in class
Static variables inside Functions Static variables when used inside function are initialized only
once, and then they hold there value even through function calls. These static variables are stored
on static storage area , not in stack. void counter() { static int count=0; cout << count++; } int
main(0 { for(int i=0;i<5;i++) { counter(); } } Output : 0 1 2 3 4 Let\'s se the same program\'s
output without using static variable. void counter() { int count=0; cout << count++; } int main(0
{ for(int i=0;i<5;i++) { counter(); } } Output : 0 0 0 0 0 If we do not use static keyword, the
variable count, is reinitialized everytime when counter() function is called, and gets destroyed
each time when counter() functions ends. But, if we make it static, once initialized count will
have a scope till the end of main() function and it will carry its value through function calls too.
If you don\'t initialize a static variable, they are by default initialized to zero. Static class Objects
Static keyword works in the same way for class objects too. Objects declared static are allocated
storage in static storage area, and have scope till the end of program. Static objects are also
initialized using constructors like other normal objects. Assignment to zero, on using static
keyword is only for primitive datatypes, not for user defined datatypes. class Abc { int i; public:
Abc() { i=0; cout << \"constructor\"; } ~Abc() { cout << \"destructor\"; } }; void f() { static Abc
obj; } int main() { int x=0; if(x==0) { f(); } cout << \"END\"; } Output : constructor END
destructor You must be thinking, why was destructor not called upon the end of the scope of if
condition. This is because object was static, which has scope till the program lifetime, hence
destructor for this object was called when main() exits. Static data member in class Static data
members of class are those members which are shared by all the objects. Static data member has
a single piece of storage, and is not available as separate copy with each object, like other non-
static data members. Static member variables (data members) are not initialied using constructor,
because these are not dependent on object initialization. Also, it must be initialized explicitly,
always outside the class. If not initialized, Linker will give error. class X { static int i; public:
X(){}; }; int X::i=1; int main() { X obj; cout << obj.i; // prints value of i } Once the definition for
static data member is made, user cannot redefine it. Though, arithmetic operations can be
performed on it. Static Member Functions These functions work for the .
Struggling with your C++ homework? Don't let complex programming concepts and challenging assignments hold you back. We're here to provide you with the ultimate solution - expert C++ homework help that guarantees your success!
CPP Homework Help is quality-oriented and has invested heavily in quality control. We have put together the best team of CPP professionals combining talent, creativity, and experience. Our experts can handle every CPP homework and ensure the student secures high grades, within their submission deadline. Every homework is plagiarism free and a turn-it-in report is issued at the time of delivery.
Reach out to our team via: -
Website: https://www.cpphomeworkhelp.com/
Email: support@cpphomeworkhelp.com
Call/WhatsApp: +1(315)557–6473
While writing program in any language, you need to use various variables to s...bhargavi804095
While writing program in any language, you need to use various variables to store various information. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
Static Keyword Static is a keyword in C++ used to give special chara.pdfKUNALHARCHANDANI1
Static Keyword Static is a keyword in C++ used to give special characteristics to an element.
Static elements are allocated storage only once in a program lifetime in static storage area. And
they have a scope till the program lifetime. Static Keyword can be used with following, Static
variable in functions Static Class Objects Static member Variable in class Static Methods in class
Static variables inside Functions Static variables when used inside function are initialized only
once, and then they hold there value even through function calls. These static variables are stored
on static storage area , not in stack. void counter() { static int count=0; cout << count++; } int
main(0 { for(int i=0;i<5;i++) { counter(); } } Output : 0 1 2 3 4 Let\'s se the same program\'s
output without using static variable. void counter() { int count=0; cout << count++; } int main(0
{ for(int i=0;i<5;i++) { counter(); } } Output : 0 0 0 0 0 If we do not use static keyword, the
variable count, is reinitialized everytime when counter() function is called, and gets destroyed
each time when counter() functions ends. But, if we make it static, once initialized count will
have a scope till the end of main() function and it will carry its value through function calls too.
If you don\'t initialize a static variable, they are by default initialized to zero. Static class Objects
Static keyword works in the same way for class objects too. Objects declared static are allocated
storage in static storage area, and have scope till the end of program. Static objects are also
initialized using constructors like other normal objects. Assignment to zero, on using static
keyword is only for primitive datatypes, not for user defined datatypes. class Abc { int i; public:
Abc() { i=0; cout << \"constructor\"; } ~Abc() { cout << \"destructor\"; } }; void f() { static Abc
obj; } int main() { int x=0; if(x==0) { f(); } cout << \"END\"; } Output : constructor END
destructor You must be thinking, why was destructor not called upon the end of the scope of if
condition. This is because object was static, which has scope till the program lifetime, hence
destructor for this object was called when main() exits. Static data member in class Static data
members of class are those members which are shared by all the objects. Static data member has
a single piece of storage, and is not available as separate copy with each object, like other non-
static data members. Static member variables (data members) are not initialied using constructor,
because these are not dependent on object initialization. Also, it must be initialized explicitly,
always outside the class. If not initialized, Linker will give error. class X { static int i; public:
X(){}; }; int X::i=1; int main() { X obj; cout << obj.i; // prints value of i } Once the definition for
static data member is made, user cannot redefine it. Though, arithmetic operations can be
performed on it. Static Member Functions These functions work for the .
Struggling with your C++ homework? Don't let complex programming concepts and challenging assignments hold you back. We're here to provide you with the ultimate solution - expert C++ homework help that guarantees your success!
CPP Homework Help is quality-oriented and has invested heavily in quality control. We have put together the best team of CPP professionals combining talent, creativity, and experience. Our experts can handle every CPP homework and ensure the student secures high grades, within their submission deadline. Every homework is plagiarism free and a turn-it-in report is issued at the time of delivery.
Reach out to our team via: -
Website: https://www.cpphomeworkhelp.com/
Email: support@cpphomeworkhelp.com
Call/WhatsApp: +1(315)557–6473
Get help with C++ homework. Now you Don't have to look the other way. here we help you with your all educational needs. We provide university-based homework help that mainly includes United States (USA) university assignment help, Canada university assignment help, United Kingdom (UK) university assignment help, Australia university assignment help, and many more all over the world. Our experts have successfully done this for the past several years. Visit us at https://www.cpphomeworkhelp.com/
I am Frank P. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Malacca, Malaysia. I have been helping students with their homework for the past 9 years. I solve homework related to C++ Programming .
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Jeremy P. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Loughborough University, UK. I have been helping students with their homework for the past 8 years. I solve homework related to C++ Programming .
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Baddie K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Arnold H. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Sheffield, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++ Programming.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Jayson L. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Sheffield, UK. I have been helping students with their homework for the past 8 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Moffat K. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from London, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++ Programming.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Daniel N. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from the University of Leeds, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Jason B. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Princeton University, USA. I have been helping students with their homework for the past 5 years. I solve homework related to C++ Programming.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Thanasis F. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Harvard University. I have been helping students with their homework for the past 5 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Jeremy P. I am an Online C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Loughborough University, UK. I have been helping students with their homework for the past 9 years. I solve homework related to Online C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Online C++ Homework.
I am Leonard K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from the University of Arkansas, USA. I have been helping students with their homework for the past 9 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Cage T. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from the University of California, USA. I have been helping students with their homework for the past 6 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Bianca H. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from, the University of Nottingham, UK. I have been helping students with their homework for the past 7 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Baddie K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Josh U. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from St. Edward’s University, USA. I have been helping students with their homework for the past 5 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Online CPP Homework Help
1. For any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at :- info@cpphomeworkhelp.com or
reach us at :- https://www.cpphomeworkhelp.com/
2. Initializer syntax:
Some parts of the initialization of a class should not be performed directly in code. In
particular, when a derived class is instantiated (i.e. when its constructor is called), the
constructors of all its base classes are also called, but these constructors may require
arguments, and the constructors are called automatically even before the code in the derived
constructor is executed. Similarly, any reference data members must be initialized as they are
created; they cannot be reassigned to point to different data within the constructor. C++
provides the initializer syntax to allow custom initialization of constructors and data members:
DerivedClass::DerivedClass() :
BaseClass(someNumber) {
…
}
This allows calling the base class constructor with an argument.
For initializing data members, the structure of this sort of statement is as follows:
class_name::class_name(argument_list) :
firstDataMemberToInitialize(initialValue1),
secondDataMemberToInitialize(initialValue2) {
…
}
cpphomeworkhelp.com
3. This initialization method – the colon after the constructor arguments, followed by a comma-
separated list of initializations to perform – can be used for any base class constructor or
data member. It can also be used to call one constructor from another.
To give one more example of the use of this syntax, a colorable Square class that inherits
from a black- and-white Rectangleclass might want to define a constructor like this:
Square::Square(int sideLength, int colorCode) : Rectangle(sideLength,
sideLength), color(colorCode) {
…
}
Though some data members can be set directly with assignment statements within the
constructor, base class constructors, data member constructors, references, and const data
members must be initialized with this syntax.
Problem 1
a. Create a Timeclass that stores a time as a single number of type time_t (this is just
another name for a certain type of integer). The constructor should take one argument –
the initial value
to set the internally stored time to. This argument should have a default value of time(0)
(the timefunction is defined in the C++ Standard Library header <ctime>, and the 0
indicates that it should use the current time). Also create a getter function for the time
stored in Time objects, and a setter function to allow changing the time the Timeobject
stores later on.
cpphomeworkhelp.com
4. Create a class called Complexfor performing arithmetic with complex numbers. Write a
program to test your class.
Complex numbers have the form realPart +
imaginaryPart * i
where i is 1 .
Use double variables to represent the private data of the class. Provide a constructor that
enables an object of this class to be initialized when it is declared. The constructor should
contain default values in case no initial values are provided (a reasonable default number
to set a complex number to is 0 0i ). Provide public member functions that perform the
following tasks:
a.Adding another Complex number: The real parts are added together and the
imaginary parts are added together.
b.Subtracting another Complex number: The real part of the right operand is
subtracted from the real part of the left operand, and the imaginary part of the right
operand is subtracted from the
imaginary part of the left operand.
c. Multiply by another Complex number: The product of the imaginary parts is
subtracted from the product of the real parts to get the new real part, and the
products of the imaginary and real and real and imaginary parts are added to form
the new imaginary part.
b. Rewrite the constructor to use the member initializer syntax instead of an assignment
statement.
Problem 2
cpphomeworkhelp.com
5. c. Print Complex numbers in the form (a, b), where a is the real part and b is the imaginary
part. The member functions should each return another Complex object, and should be
called with a syntax
like complex1.add(complex2);.
friend Functions and friend Classes:
A friend function of a class is defined outside that class's scope, yet has the right to access
the non- public (and public) members of the class. Standalone functions or entire classes
may be declared to be friends of another class.
If, for example, we wanted to declare a class to represent a person and a class to represent a
dog, but we wanted to allow any object of the Person class to access any private data or
functions of Dog objects, we might declare:
class Dog {
friend class Person;
…
};
If we only want to allow the Person’s Walk function to access private members Dog class,
and we’ve already declared the Person class (or have placed the declaration class Person;)
earlier in the file,
we could specify:
class Dog {
friend void Person::Walk();
cpphomeworkhelp.com
6. …
};
Static Class Members:
There is an important exception to the rule that each object of a class has its own copy of all
the data members of the class. In certain cases, only one copy of a variable should be
shared by all objects of a class. A static data member is used for these and other reasons.
The declaration of a static member begins with the static keyword. Although they may seem
like global variables, a class’s static data members have class scope. Also, static members
can be declared public, private or protected.
Member functions can also be declared static, meaning that no instance of a class is needed
to access them. For instance, if we had a MartianInvader class which stored a class-wide
static variable martianCount, we might define a static function getMartianCountas follows:
static const int getMartianCount() { return martianCount; }
Any static class member can be accessed from within a class function. Additionally, any
public class member can be accessed either via an object of the class or via the class name;
the two definitions of count below are equivalent:
MartianInvader myMartian;
int count = myMartian.getMartianCount();
int count = MartianInvader::getMartianCount(); //Use scope resolution operator (::)
Static member functions cannot access or modify non-static member data.
cpphomeworkhelp.com
7. Constant Member Functions:
Declaring a member function with the const keyword specifies that the function is a
“read-only” function that does not modify the object on which it is called.
To declare a constant member function, place the const keyword after the closing
parenthesis of the argument list. The const keyword is required in both the declaration
and the definition. A constant member function cannot modify any data members or call
any member functions that aren't also declared const.
const int Date::getMonth() const
{
return month; // Doesn't modify anything; trying to modify a data member
} // from here would be a syntax error
If an object of class Date would be declared as const Date tomorrow;, no non-const
member functions could be called on it.
Problem 3
Find the errors in the following class and explain how to correct them.
class StockPurchase { public:
StockPurchase(const double newPrice) {
// When someone buys a stock, modify the default price
// according to how much they were willing to pay
cpphomeworkhelp.com
8. previousDefaultPrice = defaultPrice;
currentPrice = newPrice; defaultPrice =
previousDefaultPrice
+ (currentPrice - previousDefaultPrice) / 2.0; timeLastChecked =
time(0); // record the current timestamp
}
static const double getDefaultPrice() { return
previousDefaultPrice
+ (currentPrice - previousDefaultPrice) / 2.0;
}
// Returns the current time, updating the timestamp to show
// that this object was read recently const double
getCurrentPrice() const {
timeLastChecked = time(0); return currentprice;
}
private:
double previousDefaultPrice, currentPrice; static double
defaultPrice;
time_t timeLastChecked; // A time_t is basically just an integer
}
Problem 4
cpphomeworkhelp.com
9. Fill in the blanks in each of the following statements (you may wish to refer to the chart on
Page 15 of the lecture notes):
1.A base class’s members can be accessed only in the base-class definition or in
derived-class definitions.
2.A base class’s members are accessible within that base class and anywhere that the
program has a handle to an object of that base class or to an object of one of its derived
classes.
3.A base class’s protected access members have a level of protection between those of
public and
access.
4.When deriving a class from a base class with public inheritance, public members of
the base class become _ members of the derived class, and protected
members of the base class become _ members of the derived class.
5.When deriving a class from a base class with protected inheritance, public members of
the base class become _ members of the derived class, and protected
members of the base class become _ members of the derived class.
Problem 5
Create an inheritance hierarchy containing base class Account and derived classes
SavingsAccount and CheckingAccount that inherit from class Account. Make sure all
return values, arguments, and member functions are declared const where appropriate.
cpphomeworkhelp.com
10. a.Base class Account should include one data member of type double to represent the
account balance. The class should provide a constructor that receives an initial balance
and uses it to initialize the data member. The constructor should validate the initial
balance to ensure that it is greater than or equal to 0.0. If not, the balance should be set to
0.0 and the constructor should display an error message, indicating that the initial balance
was invalid. (You may wish to use the cerr object, which functions just like cout except that
it outputs to the standard error output rather than standard text output. Usually, but not
always, the two are functionally similar.)
The class should provide four member functions. Member function Credit should add an
amount to the current balance. Member function Debit should withdraw money from the
Account and ensure that the debit amount does not exceed the Account's balance. If it
does, the balance should be left unchanged and the function should print the message
"Debit amount exceeded account balance." Member function getBalance should return the
current balance.
b.Derived class SavingsAccount should inherit the functionality of an Account, but also
include a data member of type double indicating the yearly interest rate (percentage)
assigned to the Account. SavingsAccount's constructor should receive the initial balance,
as well as an initial value for the SavingsAccount's interest rate. (Make sure to call the
base class constructor appropriately.) SavingsAccount should provide a public member
function calculateInterest that returns a double indicating the amount of interest earned by
an account. Member function calculateInterest should take one integer argument
indicating the number of years gone by, and should determine the interest amount by the
cpphomeworkhelp.com
11. formula I B * (1 r)t
, where I is the interest, B is the initial balance, r is the interest rate,
and t is the number of years gone by. [Note: SavingsAccount should inherit member
functions credit and debit as is without redefining them.]
c. Derived class CheckingAccount should inherit from base class Account and include an
additional data member of type double that represents the fee charged per transaction.
CheckingAccount's constructor should receive the initial balance, as well as a parameter
indicating a fee amount. Class CheckingAccount should redefine member functions Credit
and Debit so that they subtract the fee from the account balance whenever either
transaction is performed successfully. CheckingAccount's versions of these functions
should invoke the base- class Account version to perform the updates to an account
balance. CheckingAccount's debit function should charge a fee only if money is actually
withdrawn (i.e., if the debit amount does not exceed the account balance).
[Hint: Define Account's Debit function so that it returns a bool indicating whether money
was withdrawn. Then use the return value in the CheckingAccount version of the function
to determine whether a fee should be charged.]
Write a program that creates objects of each class and tests their member functions. Add
interest to the SavingsAccount object by first invoking its calculateInterest function, then
passing the returned interest amount to the object's Creditfunction.
Classes and header files:
Usually a class is defined in two separate files: a header file and an implementation file. If
you are
defining a class SomeClass, typically you would put the class declaration (class
SomeClass {…};) in a SomeClass.h file with function prototypes only, and then give all
cpphomeworkhelp.com
12. the function definitions in a SomeClass.cpp file (which includes SomeClass.h). The major
exception to this is functions that are just one statement, such as getter and setter functions,
which are usually small enough to fit into the header file.
This makes for a modular program setup: main is in some file like main.cpp, and SomeClass is
defined in SomeClass.h and SomeClass.cpp. You must then compile both main.cpp and
SomeClass.cpp and link them together to get the final executable.
Problem 6
Define an Array class that expands the functionality of C++ arrays. Show how you would split
your definition into an Array.h file and an Array.cpp file.
The class should contain one data member that is a pointer to a dynamically allocated array of
integers, and an integer that stores the current size of the array. The size integer should be
const – it should not be changeable after the class constructor is called.
The class should have 3 constructors: one that takes just a number of elements to allocate
(initializing them all to 0), another that takes a number of elements and an array of initial
elements, and a copy constructor that allocates a new array of the same size as the Array that
is being copied, and then copies the elements one by one.
Define 4 member functions: getLength to return the number of elements in the Array;
getElement to take an integer n and return a modifiable reference to the (n+1)th element of the
array; another getElement function that is declared const and returns a non-modifiable
reference; and a print function that takes a separator string and prints the elements one by one
separated by the separator string. (For instance, myArray.print("n") should print the array
elements with newlines between each pair.)
cpphomeworkhelp.com
13. Also define a destructor to deallocate the memory that was allocated to the internal array when
the
Array object is destroyed.
You do not need to define a main function that actually uses this class, but it will presumably be
useful for testing purposes to try creating a few Arrayobjects and manipulating them.
cpphomeworkhelp.com
14. Problem 1
(a)
#include <ctime>
class Time
{
time_t t;
public:
// or long, or int
Time( long initialTime = time(0) )
{
t = initialTime;
}
long getTime()
{
return t;
};
void setTime(long newTime)
{
t = newTime;
};
};
(b)
#include <ctime>
// or long, or int
cpphomeworkhelp.com
15. Time(time_t initialTime = time(0) ) : t(initialTime) {} int getTime()
{
return t;
}
void setTime(time_t newTime)
{
t= newTime;
}
};
Problem 2
#include <iostream>
using namespace std;
class Complex
{
double real, imaginary;
public:
Complex(double realPart=0, double imagPart=0) {real=realPart;
imaginary=imagPart;}; double getReal()
class Time
{
time_t t; public:
cpphomeworkhelp.com
17. };
};
Problem 3 (UNGRADED)
Error 1: The first occurs in function getIncrementedData. The function is declared const,
but it modifies the object.
Correction: To correct the first error, remove the const keyword from the definition
of getIncrementedData.
Error 2: The second error occurs in function getCount. This function is declared static,
so it is not allowed to access any non-static member of the class.
Correction: To correct the second error, remove the output line from the getCount
definition.
Problem 4
1.A base class’s protected members can be accessed only in the base-class definition
or in derived-class definitions.
1.A base class’s public members are accessible within that base class and anywhere
that the program has a handle to an object of that base class or to an object of one of its
derived classes.
2.A base class’s protected access members have a level of protection between those of
public and
private access.
cpphomeworkhelp.com
18. 4.When deriving a class from a base class with public inheritance, public members of the base
class become public members of the derived class, and protected members of the base
class become protected members of the derived class.
5.When deriving a class from a base class with protected inheritance, public members of the
base
class become protected members of the derived class, and protected members of the base
class become protected members of the derived class.
Problem 5
#include <iostream> #include <cmath> using
namespace std;
class Account //part A
{
double balance; public:
Account(double initBalance);
void Credit(double amountToCredit); bool Debit(double
amountToDebit); double getBalance();
};
Account::Account(double initBalance):balance(initBalance)
{
if(balance<0.0)
{
cpphomeworkhelp.com