in c++, create a struct named piggybank. this struct is meant to be hold the number of each US currency coins in the piggybank.Next, write a function that will take this struct and an integer value as argument and increment the coin in the struct depending on the integer value. If the value is not a valid US coin the function will return false. Do this without using any if/else statement.
SOURCE CODE IN C++:
#include <iostream>
using namespace std;
//struct to hold the number of each US currency coins in the piggybank
struct piggybank
{
int pennies, nickels, dimes, quarters, dollars;
piggybank()
{
pennies=0;
nickels=0;
dimes=0;
quarters=0;
dollars=0;
}
};
//Function that will take piggybank struct and an integer
//value as argument and increment the coin in the struct
//depending on the integer value
bool addCoin(piggybank &p, int coin)
{
//using switch case to find value and increment
switch(coin)
{
case 1:
p.pennies+=1;
return true;
case 5:
p.nickels+=1;
return true;
case 10:
p.dimes+=1;
return true;
case 25:
p.quarters+=1;
return true;
case 100:
p.dollars+=1;
return true;
default: //if it is not a valid value
return false;
}
}
int main()
{
//testing the function and struct
piggybank p;
addCoin(p,5);
addCoin(p,25);
addCoin(p,10);
addCoin(p,25);
addCoin(p,5);
addCoin(p,45); //since 45 is not valid, no change is seen
addCoin(p,5);
cout << "Coins in the piggybank:" << endl;
cout << "Pennies: " << p.pennies << endl;
cout << "Nickels: " << p.nickels<< endl;
cout << "Dimes: " << p.dimes << endl;
cout << "Quarters: " << p.quarters << endl;
cout << "Dollars: " << p.dollars << endl;
return 0;
}
OUTPUT:

in c++, create a struct named piggybank. this struct is meant to be hold the number...
Create a class named Cash. Include one private integer variable to hold the number of dollars and one to hold the number of cents. Create your own accessor and mutator functions to read and set both member variables. Create a function that returns the amount of money as a double. Test all of your functions. Use at least 4 Cash objects. Must be done in c++
CODE IN C++ Given: typedef char ItemType; // a struct type named NodeType that includes a ItemType and pointer // (to a NodeType) field struct NodeType { ItemType value; NodeType * next; }; bool Delete (NodeType * & firstPtr, ItemType value) { NodeType * prev, * cur; cur = Search (firstPtr, value, prev); if (cur==NULL) return false; else { // remove cur node from the linked list if (prev!=NULL) { //not the first one prev->next = cur->next;...
C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array named f, and one double array named d, each of size M. (b)Declare array x with N of those structs. (c)Write a void function to traverse array x (using a pointer) assigning to each element in each array d (in each struct in array x) the sum of the corresponding elements in arrays i and f (in the same struct). Use 3 pointers (of...
implement a class called PiggyBank that will be used to represent a collection of coins. Functionality will be added to the class so that coins can be added to the bank and output operations can be performed. A driver program is provided to test the methods. class PiggyBank The PiggyBank class definition and symbolic constants should be placed at the top of the driver program source code file while the method implementation should be done after the closing curly brace...
Create a new file named spherevolume.py that does the following: Define a function named sphereVolume that accepts a radius value as an argument and returns (not prints) the volume of a sphere with that radius. Write code to test your function with the following inputs: sphereVolume(2.0) // should return 33.510321638291124 or a number close to it. sphereVolume(5.0) // should return 523.5987755982989 or a number close to it.
JAVA PROG HW Problem 1 1. In the src −→ edu.neiu.p2 directory, create a package named problem1. 2. Create a Java class named StringParser with the following: ApublicstaticmethodnamedfindIntegerthattakesaStringandtwocharvariables as parameters (in that order) and does not return anything. The method should find and print the integer value that is located in between the two characters. You can assume that the second char parameter will always follow the firstchar parameter. However, you cannot assume that the parameters will be different from...
a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name. "XXX", the apartment number to O, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy...
1. Write a statement that calls a function named showSquare, passing the value 10 as an argument. 2. Write the function prototype for a function called showSquare. The function should have a single parameter variable of the int data type and areturn type of void. 3. Write the function prototype for a function called showScoreswith a parameter list containing four integer variables and a return type of void. 4. Look at the following function definition: double getGrossPay(int hoursWorked, double payRate)...
##8. A program contains the following function definition: ##def cube(num): ##return num * num * num ##Write a statement that passes the value 4 to this function and assigns its return value ##to the variable result. ##9. Write a function named times_ten that accepts a number as an argument. When the ##function is called, it should return the value of its argument multiplied times 10. ##10. Write a function named is_valid_length that accepts a string and an integer as ##arguments....
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...