please help me urgently!

question:


(Account Class) Create an Account class that a bank might use to represent customers’ bank accounts. Include a data member of type int to represent the account balance. [Note: In subsequent chapters, we’ll use numbers that contain decimal points (e.g., 2.75)—called floating-point values— to represent dollar amounts.] 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’s greater than or equal to 0. If not, set the balance to 0 and display an error message indicating that the initial balance was invalid. Provide three 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 a message indicating "Debit amount exceeded account balance." Member function getBalance should return the current balance. Create a program that creates two Account objects and tests the member functions of class Account.






answer:

This is not a homework service. Post your attempt and ask specific questions about where you are stuck...
#include <iostream>

using namespace std;

//creating account class
class Account
{
public:
Account ( int );
void setBalance( int );
int getBalance();
void debitBalance( int );
void creditBalance( int );
private:
int balance; // bank account balance name
};


#include <iostream>

using namespace std;

#include "Account.h"

//initialization with constructor, with supplied args
Account::Account ( int initialBalance )
{
if (initialBalance >= 0)
setBalance ( initialBalance );
cout << "Account balance set without any problem" << endl;

if (initialBalance < 0)
{
balance = 0;
cout << "Account balance cannot be negative. Account amount set as 0" << endl;
}
}

void Account::setBalance(int newbalance)
{
balance = newbalance;
}

void Account::debitBalance( int debit )
{
if (debit > balance)
cout << "Your balance is not enough!\n";
else
{
balance = balance - debit;
}

}
void Account::creditBalance( int credit)
{
balance =balance + credit;
}
int Account::getBalance()
{
return balance;
}




include <iostream>
#include "Account.h"
using namespace std;



int main()
{
Account account1( 1111 );
Account account2( -1111 );

int choise;
int accountNo;
int debAmount;
int credAmount;

//display initial balances

cout << "Initial balance of account1 is " << account1.getBalance() << endl;


cout << "Initial balance of account2 is " << account2.getBalance() << endl;



cout<<"please choice your account"<<endl;



cout<<"1-myaccount1"<<endl;



cout<<"2-myaccount2"<<endl;



cin>> accountNo;


switch(accountNo){

case 1:
cout << "\nPlease select the transaction (enter the number):" << endl;
cout << "1. Balance Inquiry" << endl;
cout << "2. Debit" << endl;
cout << "3. Credit" << endl;
cin>>choise;
switch (choise){
case 1:
cout << "account1 balance: " << account1.getBalance() << endl;
break;
case 2 :
cout << "enter debit amount: " << endl;
cin >> debAmount;

account1.debitBalance(debAmount);

cout << "current balance is " << account1.getBalance() << endl;
break;
case 3:

cout << "enter credit amount: " << endl;
cin >> credAmount;

account1.creditBalance(credAmount);
cout << "current balance is " << account1.getBalance() << endl;
break;

}
break;
case 2 :


cout << "\nPlease select the transaction (enter the number):" << endl;
cout << "1. Balance Inquiry" << endl;
cout << "2. Debit" << endl;
cout << "3. Credit" << endl;
cin>>choise;


switch (choise){
case 1:
cout << "account2 balance: " << account2.getBalance() << endl;
break;
case 2 :
cout << "enter debit amount: " << endl;
cin >> debAmount;

account1.debitBalance(debAmount);
cout << "current balance is " << account2.getBalance() << endl;
break;
case 3:

cout << "enter credit amount: " << endl;
cin >> credAmount;
account2.creditBalance(credAmount);
cout << "current balance is " << account2.getBalance() << endl;
break;

}
}
}






it make error

Error 1 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

Error 2 error LNK1120: 1 unresolved externals


what is the problem please help me ! for solving


Please edit your post and use the tags [ code ] and [ /code ] Format: <>
if you give example ı wil be happy you show me please because i'm beginner

Enter your code like this:

[ code ]
#include <iostream>

int main()
{
std::cout << "hello world";

return 0;
}
[ /code ]

will give you...
1
2
3
4
5
6
7
8
#include <iostream>

int main()
{
    std::cout << "hello world";

    return 0;
}


And DO NOT repost your questions in new topics just cause you dont get an answer.
Last edited on
not again

Can you edit because i spend much time for this code but i did not understand it's very important for me since it is homework
I made this for you. I have not corrected all the errors, but I did put in a few comments on your code and minor mistakes.

OBS!!!
This is not a sulotion nor is it my work! This is simply the same code as the one posted above, but I did put it inside codetags to make it readable!



.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

 using namespace std;

 //creating account class
 class Account
 {
     public:
         Account ( int );
         void setBalance( int );
         int getBalance();
         void debitBalance( int );
         void creditBalance( int );
     private:
         int balance; // bank account balance name
 };


.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include "Account.h" // keep your code sorted

 using namespace std;
 

 //initialization with constructor, with supplied args
 Account::Account ( int initialBalance )
 {
     if (initialBalance >= 0)
     setBalance ( initialBalance );
     cout << "Account balance set without any problem" << endl;

     if (initialBalance < 0)
     {
         balance = 0;
         cout << "Account balance cannot be negative. Account amount set as 0" << endl;
     }
 }

 void Account::setBalance(int newbalance)
 {
     balance = newbalance;
 }

 void Account::debitBalance( int debit )
 {
     if (debit > balance)
         cout << "Your balance is not enough!\n"; 

     else
     { 
        balance = balance - debit;
     }

 }
 
void Account::creditBalance( int credit)
 {
     balance =balance + credit;
 }
 
int Account::getBalance()
 {
     return balance;
 }
 


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

#include <iostream> // dont forget the # before include
#include "Account.h"
using namespace std;

 

int main()
 {
     Account account1( 1111 );
     Account account2( -1111 );

     int choise;
     int accountNo;
     int debAmount;
     int credAmount; 

    //display initial balances

    cout << "Initial balance of account1 is " << account1.getBalance() << endl; 

    cout << "Initial balance of account2 is " << account2.getBalance() << endl;

    cout<<"please choice your account"<<endl;
 
    cout<<"1-myaccount1"<<endl;
 
    cout<<"2-myaccount2"<<endl;
 
    cin>> accountNo;
 
    switch(accountNo)
    {   //be consequent in how you type your code
        case 1:
            cout << "\nPlease select the transaction (enter the number):" << endl;
            cout << "1. Balance Inquiry" << endl;
            cout << "2. Debit" << endl;
            cout << "3. Credit" << endl;
            cin>>choise;

            switch (choise)
           {
                case 1:
                    cout << "account1 balance: " << account1.getBalance() << endl;
                    break;
                case 2 :
                    cout << "enter debit amount: " << endl;
                    cin >> debAmount;
    
                    account1.debitBalance(debAmount);
 
                    cout << "current balance is " << account1.getBalance() << endl;
                    break;
                case 3:
 
                    cout << "enter credit amount: " << endl;
                    cin >> credAmount;

                    account1.creditBalance(credAmount);
                    cout << "current balance is " << account1.getBalance() << endl;
                    break;
 
            }//END switch(choise) case 1
            break;

        case 2 :
            cout << "\nPlease select the transaction (enter the number):" << endl;
            cout << "1. Balance Inquiry" << endl;
            cout << "2. Debit" << endl;
            cout << "3. Credit" << endl;
            cin>>choise;
 
            switch (choise)
            {
                case 1:
                    cout << "account2 balance: " << account2.getBalance() << endl;
                    break;
                case 2 :
                    cout << "enter debit amount: " << endl;
                    cin >> debAmount;

                    account1.debitBalance(debAmount);
                    cout << "current balance is " << account2.getBalance() << endl;
                    break;
                case 3:
                    cout << "enter credit amount: " << endl;
                    cin >> credAmount;
                    account2.creditBalance(credAmount);
                    cout << "current balance is " << account2.getBalance() << endl;
                    break;

            }//END switch(choise) case 2

        }// ENDswitch(accountNo)

}
Last edited on
closed account (3qX21hU5)
Giving him most of the program solves nothing and will hurt him in the long run. If he isn't even going to try and accept help to work through it on his own and just keeps asking for the answer ignore him because programming is probably not for him. Programming is not a copy and paste profession and if he can't take the time to research his problems and correct them himself (With guidance of others) he is going to fail plain and simple. Because 90% of the time you won't be programming you will be researching, debugging, and a whole bunch of other things so might as well learn to do it now.
Last edited on
Zereo
All I did was taking his code and put it inside codetags to make it more readable. Did not do any work on it exept putting in a few comments. I will not solve the problem for him, but someone might be able to give him a hint if they can read what he has done.
Last edited on
closed account (3qX21hU5)
Ahh my mistake then (Should have taken the time and looked through the code ;P) and sorry for that, it was more meant for the OP and it still stands. You are going to need to be able to walk through your code and find the bugs in it. Other people will help you by pushing you in the right direction like Hashimatsu did but they won't just fix it for you.
Last edited on
Topic archived. No new replies allowed.