Question 1 Rewrite the programme given in ‘Assignment 1- Question 3’ using functions. There should be 4 functions defined in your programme. Function 1: A function which displays the Menu. Function 2: A function which calculates the current in an electrical circuit. Function 3: A function which calculates the acceleration of a car Function 4: A function which calculates the intercept of a straight line graph
Question 2 Declare an array, which can hold 5 integer elements. The user should be given the opportunity to enter 5 values into the array from the keyboard. a) Using a pointer, store the values that the user has entered in the array. b) Calculate and display the average of the array elements. c) Arrange the values in the array according to descending order (from the highest value to the lowest value) and display the answer. Hint: You should use nested loops and a temporary variable in order to arrange the values in descending order.
Question 3 You need to write a password registration programme. Your programme should be structured in the flowing way. Take user input (first name, last name, user name, password Password more than 7 characters
Password less than 7 characters
Ask the user to reenter password
Take user input (password)
Password more than 7 characters Password re-entered correctly Display login details
Password re-entered incorrectly Programme quit
Password less than 7 characters
At the start of your programme, the user should be given the opportunity to enter his/her first name, last name, a user name and a password separately. The password should have a minimum of 7 characters. If the password is less than 7 characters, your programme should display an error message and give the opportunity for the user to enter a password again and again until the user enters a password of more than 7 characters. If the password is more than 7 characters your programme should ask the user to re-enter password in order to confirm the password that he/she has entered. If the user has re-entered a different password the programme should display and error message and should quit the programme. If the re-entered password matches with the previously entered password, your programme should display the following output on the screen. *******Your Login Details ****** Name: Nimal Perera User Name: NPerera Password: book001 Hint: Use string functions.
Question 4 Write a programme, which is a bank account, which records the balance of money for a given customer. Your programme should perform the three transactions given below. a) Checking the bank balance- Bank balance may have a positive or credit balance where the bank holds money on behalf of the customer; or a negative or debit balance where the customer owes the bank money. If the bank balance is a negative value you should display a message indicating that the customer has a debit value. If the bank balance is zero you should display a message indicating that the account has no money. b) Deposit money – The money that the customer deposits should be added to the balance. c) Withdraw money- The money that the customer withdraws should be deducted from the balance. Define a class called ‘Account’. You should define three different public member functions in order to carry out the above three transactions and a private member data called ‘balance’ in order to perform the calculations. Define a constructor which initializes the default bank balance to zero (0). You should define a destructor for the class as well. Create three objects as given below and perform the following transactions and display the balance to the user.
Object Name Nimal Kamal Saman
Initial Balance 0 100 -400
Deposit 500 400 400
Withdrawal 200 -
Balance ? ? ?