Ques Ans
Ques Ans
Employee Number, Employee Name, Department, Basic Salary, Bonus and Tax.
Write a program to input data of any number of employee and display the same input data with net
salary of each employee, Where Net Salary - Basic Salary + Bonus-Tax
#include <iostream>
#include <vector>
#include <string>
class Employee {
private:
int employeeNumber;
string employeeName;
string department;
double basicSalary;
double bonus;
double tax;
public:
// Constructor
Employee(int number, string name, string dept, double salary, double bonusAmt, double taxAmt) {
employeeNumber = number;
employeeName = name;
department = dept;
basicSalary = salary;
bonus = bonusAmt;
tax = taxAmt;
}
// Method to calculate net salary
double calculateNetSalary() {
void displayEmployeeData() {
};
int main() {
int n;
cin >> n;
vector<Employee> employees;
int empNum;
cout << "Enter details for employee " << i + 1 << ":" << endl;
cin.ignore();
getline(cin, empName);
getline(cin, dept);
employees[i].displayEmployeeData();
return 0;
}
4. Design an application for a bank with account number, account holder, city and opening balance as
data members. Use constructor and destructor in your application. Use two additional functions
deposit) to deposit cash in a particular account number account and withdraw() to withdraw cash
from a particular account number account.
#include <iostream>
#include <string>
#include <map>
class Bank {
private:
int accountNumber;
string accountHolder;
string city;
double openingBalance;
public:
// Constructor
accountNumber = accNum;
accountHolder = accHolder;
city = cityName;
openingBalance = openingBal;
// Destructor
~Bank() {
}
// Function to deposit cash
openingBalance += amount;
cout << "Amount deposited successfully. Current balance: " << openingBalance << endl;
} else {
openingBalance -= amount;
cout << "Amount withdrawn successfully. Current balance: " << openingBalance << endl;
void displayAccountDetails() {
};
int main() {
// Creating accounts
Bank *acc1 = new Bank(1001, "John Doe", "New York", 5000);
accounts[1001] = acc1;
accounts[1002] = acc2;
accounts[1001]->deposit(2000);
accounts[1002]->withdraw(3000);
accounts[1001]->displayAccountDetails();
accounts[1002]->displayAccountDetails();
// Deleting accounts
delete acc1;
delete acc2;
return 0;
}
6. b) What do you mean by default parameter(s) of a function? Explain with the help of an example.
Default parameters in a function refer to the values assigned to parameters that are automatically
used if the caller doesn't provide a value for those parameters. They allow functions to be more
flexible by providing default behavior while still allowing customization when necessary.
cpp
#include <iostream>
cout << "Hello, " << name << "!" << endl;
int main() {
return 0;
In this example, the greet function has a default parameter name set to "Guest". When the function
is called without providing a parameter, it uses the default value "Guest". However, if a parameter is
provided (e.g., "Alice"), it overrides the default value and uses the provided value instead.
8. b) Write a program on data conversions
Sure, here's a simple C++ program that demonstrates data conversions from object to float data type
and from float data type to object:
cpp
#include <iostream>
#include <typeinfo>
int main() {
Object obj = 10; // Assuming Object is a class that holds an integer value
return 0;
Replace Object with the appropriate class name you are using, and adjust the conversion logic
accordingly based on your actual implementation.
9. b) How will you use class templates in a C++ program? Explain with example.
In C++, class templates provide a way to create generic classes that can work with any data type.
They allow you to define a blueprint for a class without specifying the actual data type it will work
with. This provides flexibility and reusability in code, as you can create instances of the class with
different data types while still maintaining a common structure and behavior.
```cpp
#include <iostream>
class Stack {
private:
public:
~Stack() {
delete[] stackArray;
if (top == capacity - 1) {
std::cout << "Stack Overflow! Cannot push more elements." << std::endl;
return;
stackArray[++top] = element;
T pop() {
if (top == -1) {
std::cout << "Stack Underflow! Cannot pop from an empty stack." << std::endl;
return stackArray[top--];
bool isEmpty() {
bool isFull() {
};
int main() {
Stack<int> intStack(5);
// Push some integers onto the stack
intStack.push(10);
intStack.push(20);
intStack.push(30);
Stack<char> charStack(3);
charStack.push('a');
charStack.push('b');
charStack.push('c');
return 0;
```
In this example, we define a template class `Stack` that can work with any data type `T`. We can
create instances of `Stack` with different data types, such as `int` and `char`, by specifying the desired
data type within angle brackets (`<>`) when declaring objects. This allows us to reuse the same stack
implementation for different types of data while maintaining type safety and code clarity.