1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
klio [65]
3 years ago
14

Write a C++ function for the following:

Computers and Technology
1 answer:
Nana76 [90]3 years ago
4 0

Solution :

class Account

$ \{ $

public:

$\text{Account}()$;

double $\text{getBalance}$();

void $\text{setBalance}$();

$\text{bool withdraw}$(double bal);

$\text{private}:$

double $\text{balance}$;

}:

$\text{Account}()$ {}

double $\text{getBalance}$()

$ \{ $

$\text{return balance}$;

}

void $\text{setBalance}$(double $\text{balance}$)

$ \{ $

this.$\text{balance}$ = $\text{balance}$;

}

$\text{boolean}$ withdraw($\text{double bal}$)

$ \{ $

if($\text{balance}$ >= bal)

$ \{ $

$\text{balance}$ = $\text{balance}$ - bal;

$\text{return}$ true;

}

$\text{return}$ false;

}

}

You might be interested in
Write a program that prompts the user to enter in a postive number. Only accept positive numbers - if the user supplies a negati
marusya05 [52]

Answer:

The c++ program to check prime numbers is shown below.

#include <iostream>

using namespace std;

int main() {

   int num, prime=0;

   do

   {

       cout<<"Enter a positive number."<<endl;

       cin>>num;

       if(num<1)

       {

           cout<<"Invalid number. Enter a positive number"<<endl;

           cin>>num;

       }

   }while(num<1);

   

   if(num==1 || num==2 || num==3)

       cout<<num<<" is a prime number."<<endl;

   else if(num%2 == 0)

       cout<<num<<" is not a prime number."<<endl;

   else

   {

       for(int k=3; k<num/2; k++)

       {

           if(num%k == 0)

               prime++;

       }    

   if(prime>1)

       cout<<num<<" is not a prime number."<<endl;

   else

       cout<<num<<" is a prime number."<<endl;

   }

}

OUTPUT

Enter a positive number.

-7

Invalid number. Enter a positive number

0

Enter a positive number.

79

79 is a prime number.

Explanation:

The user input is validated for positivity. A do while loop along with an if statement is implemented for verification.

do

   {

       cout<<"Enter a positive number."<<endl;

       cin>>num;

       if(num<1)

       {

           cout<<"Invalid number. Enter a positive number"<<endl;

           cin>>num;

       }

   }while(num<1);

The test for prime number is done by using multiple if else statements.

If user inputs 1, 2, or 3, message is displayed.

Else If user inputs an even number, message is displayed for not prime. This is done by taking modulo of the number upon division by 2.

Else if user inputs neither an even number nor a number less than 3, the modulus of the number is taken with divisors beginning from 3 up to half of the input number.

For this, an integer variable prime is initialized to 0. A number can be completely divisible by itself or by its factors.

If the number is divisible by any of the divisors, value of variable prime is increased by 1. If value of prime is greater than 1, this means that the user input is divisible by more than one divisor. Hence, the given number is not a prime number.

5 0
3 years ago
Those that work in the Printing Technology pathway are typically self-employed, and work indoors. self-employed, and work outdoo
Reika [66]
A.) Those that work in the Printing Technology pathway are typically "<span>self-employed, and work indoors"

Hope this helps!</span>
3 0
3 years ago
Read 2 more answers
A customer has a system with a Gigabyte B450 Aorus Pro motherboard. He wants to upgrade the processor from the AMD Athlon X4 950
AleksandrR [38]
This upgrade will make a big improvement from his AMD Athalon X4 950 to the AMD Ryzen 7 2700X this is because the system will have more gigabytes and a better processor
3 0
3 years ago
Read 2 more answers
Which type of polish grade uses green-colored connectors to help you keep from using the wrong connector type
Anestetic [448]

Answer:

Medium Grade Liquid Metal Polish. pls give me brainliest

8 0
2 years ago
Consider the operation of deleting the root of a binary search tree. if the root has one child, then ________.
PSYCHO15rus [73]

The reference to the root of the tree should be set to null

<h3>Can the root of a binary tree be null?</h3>
  • Only the subtrees are nulled out, the root always remains and will never be set to null.
<h3>What is null root?</h3>
  • null-, root. -null- comes from Latin, where it has the meaning "none; not one.
  • '' This meaning is found in such words as: annul, null, nullify.

To learn more about it, refer

to brainly.com/question/24448358

#SPJ4

4 0
1 year ago
Other questions:
  • ________ is a method for addressing, creating, updating, or querying relational databases.
    9·1 answer
  • An IT technician has manually configured an IP address on a laptop for a new employee. Each time the employee tries to connect t
    8·1 answer
  • I don’t know technically
    9·2 answers
  • Proponents of Internet freedom see its _____________ as providing protection for unpopular expression; proponents of greater Int
    8·1 answer
  • Which device protects computer systems from voltage fluctuations?
    14·2 answers
  • A retail company must file a monthly sales tax report listing the total sales for the month and the amount of state and county s
    11·1 answer
  • 3. Discuss microprocessor components, chips,
    15·1 answer
  • 15. Feelings (maps, coins, clues, etc.) and the invisClue books were some innovative ways used to keep __________ players engage
    8·2 answers
  • Electrical data suitable for transmission is called a(n)
    5·1 answer
  • Change the quick style gallery display
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!