I need to solve this assignment but i cant , is there anyone could solve it :(
Part A
Write the definition of a struct named Nametype which has 2 components:
1. FName of type string.
2. LName of type string.
Part B
Write the definition of a class named BankAccount which includes data members and the prototype of the function members as described below:
The data members of the class BankAccount are:
1. AccountNumber (long),
2. Name (struct NameType),
3. Balance (float).
The class BankAccount contains the following member functions:
1. A Constructor with default valued parameters where the default values are 999 for AccountNumber, "" for Name, and 0.0 for Balance.
2. Set functions for all the data members.
3. Get functions for all the data members.
4. Withdraw which is used to withdraw a certain amount X from the Account. It should check that the balance in the account is at least equal to X (i.e. X or more) before it allows the withdrawal and reduce the Balance by X.
5. Deposit which is used to Deposit a certain amount Y into the Account. It should of course increase the Balance by Y.
6. IsAccountEmpty which returns true if the Balance is less than or equal to zero. Otherwise it returns false.
7. DisplayAccountDetails that prints (on the screen) all the information about the Account.
Part C
Write the code (Implementation) of all member functions of the class BankAccount.
Part D
In the main function:
1. Write one statement to define an object named myAccount from the class BankAccount with values of 9876543, "Mohd Altaajer'', 2000 for the data members AccountNumber, Name, and Balance respectively.
2.Write statements that will withdraw an amount of 1000 from the account myAccount then prints the following messages:
Opening Balance: ppp
Amount of Withdrarwal: 1000.
Remaining Balance: nnn
Where ppp and nnn are the values of the previous balance (before the withdrawal) and the new balance (after the withdrawal) respectively.
3. Write one statement to define an array named AccountList with size 30 that contains objects of class BankAccount.
4. Input data for 3 Bank accounts.
5. Write statements to print on the screen all the empty Accounts in AccountList (that have a balance of zero or less). Assume that the list length is 3.
my problem is the program doesn't identify the Nametype , but long and float it is ok they come in blue color except the Nametype ( which is the structr ) ....
Privte :
long AccountNumber;
Nametype Name;>>>>>>>>>>> here the problem
float Balance;
In your struct:
Everything is correct there. Congratulations.
In your class:
You're missing semicolons after all the declarations which are public.
You cannot set the default values for that struct in your constructor like that.
You cannot use your struct like that. It has to have an instance like a class. So it would be something more like Nametype naem
You cannot set defaults for the struct used as a variable in your constructor. I've tried.
You cannot set the defaults for the struct's variables in your struct's definition, before you try it.
You misspelled private. Private and Public are not to be capitalized. Sorry.
In main:
You have to return something. It's the "law".
You're missing a semicolon somewhere.
There may be other errors, but if so, then I'm not telling what they are. You'll have to find them on your own.
Actually you don't have to. If you don't return anything, then your program will automatically return 0 at the end of main for you. However, it is still a good idea to be explicit about it.
@ahmedy: When you create your own structs/classes, they don't get highlighted.
Firedraco, c'mon. That's why I used "law" in double quotes as opposed to no quotes at all. I know my C++!
Ahmedy: Indeed, structs/classes that you create will not be highlighted. Unions and templates are also not highlighted.
Extra hint, though, as I'm writing this post and don't want to edit my first one: You will need to input your first and last name separately unless you know a few tricks about lexing in C++.