Professional Documents
Culture Documents
Develop a C++ program to manage bank accounts, utilizing friend functions and
constructors. The program should allow users to create and manipulate bank accounts,
including functionalities such as depositing and withdrawing funds, checking account
balances, and transferring funds between accounts. Implement a BankAccount class
with private attributes such as account number, account holder name, and balance.
Utilize a friend function to facilitate fund transfers between accounts while ensuring
appropriate access to private member variables. Additionally, design constructors to
initialize bank accounts with default or user-specified values. Develop a user-friendly
interface in the main program to interact with the bank account functionalities,
enabling users to perform transactions seamlessly. Ensure robust error handling to
manage invalid inputs and account operations effectively.
3. A class called Employee with private attributes for salary (double) and number of
hours worked per day (int). Define a constructor that initializes these attributes with
values passed as arguments.
i) Define a public method called 'getInfo()' that takes the salary and number of hours
of work per day of an employee as parameters and sets the corresponding attributes of
the Employee object.
ii) Define another public method called 'AddSal()' that adds $10 to the salary of the
employee if it is less than $500. This method should be called automatically as soon
as the Employee object is created.
iii) Define a third public method called 'AddWork()' that adds $5 to the salary of the
employee if the number of hours of work per day is more than 6.
In the main method, create an instance of the Employee class by passing the initial
salary and number of hours worked per day as arguments to the constructor. Then,
call the 'AddSal()' and 'AddWork()' methods on the Employee object to adjust the
salary based on the criteria specified. Finally, print out the final salary of the
employee to the console. Add error handling to the program by validating user input
for the salary and number of hours worked per day. Ensure that the program does not
crash or behave unexpectedly in case of invalid input. Demonstrate a C++ program
for the above scenario.
You are tasked with creating a program to manage student records using C++. Your
program should utilize an array of objects, constructors, and a friend function. Design a
solution that meets the following requirements:
Define a Student class to represent individual student records. Each student should have
the following attributes:
a. Student ID
b. Name
c. Grade
Implement a constructor for the Student class to initialize these attributes.
7. Design a C++ program that handles invalid input using try-catch blocks. Implement a
solution with the following specifications:
Define a function named calculateAverage() that calculates the average of two numbers. If
the user inputs a non-numeric value, the function should throw an exception.
Use a try-catch block within the calculateAverage() function to handle the following
exception:
If the user inputs a non-numeric value, throw an exception of type std::invalid_argument with
the message "Invalid input. Please enter numeric values".
Develop a main program that: