T1 Paper With Solution Even 2024
T1 Paper With Solution Even 2024
Even 2024
1. [CO1] [Marks 5] Design a C++ program that can compute the annual tax of an
employee. Assume that there is an Employee class having data members eid(int),
eName(string) and annualSalary(double) and a TaxDeductibles class having data
members eid(int), insurancePremium(double) and homeLoanInterest(double).
Design a non-member function that can accept one object from both the classes
and compute the tax payable by an employee (eid should match in both the
Employee and TaxDeductibles object) as per the following rules:
A. The total deduction = insurance premium + home loan interest. (Case 1)
B. The maximum limit of insurance premium is 50,000. If any employee has
insurance premium above 50,000 then only 50,000 will be considered for
deduction. (Case 2).
C. Annual Tax = 10% of (annual salary – total deductions).
Test Cases:
1. 2. 3.
Enter Employee Details… Enter Employee Details… Enter Employee Details…
eid: 123 eid: 100 eid: 123
eName: Rohit eName: Virat eName: Rohit
annualSalary: 1000000 annualSalary: 1500000 annualSalary: 1000000
Solution1
Marking Strategy
#include<iostream>
using namespace std;
class TaxDeductibles;
class Employee
{
int eid;
char eName[30];
double annualSalary;
public:
void setEmployee()
{
cout<<"\nEnter Employee Details..."<<endl;
cout<<"eid: ";
cin>>eid;
cout<<"\neName: ";
cin>>eName;
cout<<"\nannualSalary: ";
cin>>annualSalary;
}
friend void computeTax(Employee E, TaxDeductibles T);
};
class TaxDeductibles
{
int eid;
double insuarancePrem, homeLoanInt;
public:
void setDeductibles()
{
cout<<"Enter Tax Deductibles..."<<endl;
cout<<"eid: ";
cin>>eid;
cout<<"\nInsuarance Premium: ";
cin>>insuarancePrem;
cout<<"\nHome Loan Interest: ";
cin>>homeLoanInt;
}
int main(void)
{
Employee E;
TaxDeductibles T;
E.setEmployee();
T.setDeductibles();
computeTax(E,T);
return 0;
}
Marking Strategy:
1 mark for each operator overloading functions 2*1=2
1 mark for calling the operation overloading functions
1 mark for class declaration and definitions
#include<iostream>
using namespace std;
class Vector
{
double x,y;
public:
void setData()
{
cout<<"Enter x and y coordinate: ";
cin>>x>>y;
cout<<endl;
}
Vector operator*(double t)
{
Vector temp;
temp.x = x*t;
temp.y = y*t;
return temp;
}
Vector operator+(Vector V)
{
Vector temp;
temp.x = x + V.x;
temp.y = y + V.y;
return temp;
}
void display()
{
if(y>=0)
cout<<x<<"i + "<<y<<"j"<<endl;
else
cout<<x<<"i - "<<-y<<"j"<<endl;
}
};
int main(void)
{
Vector P,V,Res;
double t;
P.setData();
V.setData();
cout<<"Enter time: ";
cin>>t;
Res = P + V*t;
cout<<"\nThe final position of the boat is: "<<endl;
Res.display();
return 0;
}
Q3: [CO1] [Marks 5] Create a class called Product having the following data members:
costPrice (double), markedPrice (double) and discount (double). A product is called a feasible
product if and only if its selling price (Marked Price *(1 - discount/100)) is greater than its cost
price. Write a C++ program that will create any number of products dynamically. The program
will terminate as soon as a product is created whose selling price falls below its cost price. All
the products must be initialized via a parameterized constructor. Also display the number of
feasible products created at the end.
Test Cases:
1. Enter Product Details:
1000 2000 15
Cost Price= 1000, Marked Price = 2000, Discount= 15%, Selling Price= 1700
2. Enter Product Details:
5000 7000 10
Cost Price= 5000, Marked Price = 7000, Discount= 10%, Selling Price= 6300
3. Enter Product Details:
1000 1200 20
A total of 2 feasible products were created.
Solution 3:
Marking Strategy:
1 mark for DMA (Dynamic memory allocation)
1 mark for test case verification
1 mark for verifying termination condition
1 mark for class definition
1 mark for main function including calling function using pointer object.
#include <iostream>
#include <string>
using namespace std;
class Product
{
double cp, mp, disc;
static int count;
public:
Product(){}
Product(double c, double m, double d)
{
count++;
cp = c;
mp = m;
disc = d;
}
double getSP()
{
return mp*(1-disc/100);
}
void display()
{
cout<<"Cost Price= "<<cp<<", Marked Price = "<<mp<<", Discount=
"<<disc<<"%, "<<"Selling Price= "<<getSP()<<endl;
}
int getCount()
{ return count; }
double getCP() { return cp; }
};
int main()
{
double c,m,d;
Product *P;
while(1)
{
cout<<"Enter Product Details: "<<endl;
cin>>c>>m>>d;
P = new Product(c,m,d);
if(P->getCP() < P->getSP())
{
P->display();
continue;
}
else
{
break;
}
}
//cout<<" A total of "<<(Product::count) - 1 <<" feasible products were
created."<<endl;
cout<<" A total of "<<(P->getCount()) - 1 <<" feasible products were
created."<<endl;
return 0;
}
Q4: [CO1] [Marks 2*3=6] Find the output with suitable explanation for the below given snippets:
a) #include<iostream> b) #include <iostream> c) #include <iostream>
using namespace std; void modifyArray(int* arr, int size) void processArray(int* arr, int
class Number { { size) {
for (int i = 0; i < size; ++i){ for (int i = 0; i < size; ++i) {
public: *arr = (*arr++ * 2) + 5; arr[i] = 2*arr[i] * 2; }}
int x; arr++; }}
int main() {
Number (){ int main() { int* originalArray = new int[5];
x=10; } int arr[] = {10, 20, 30, 40, 50};
for (int i = 0; i < 5; ++i) {
Number (int y=5) { int len = sizeof(arr) / sizeof(arr[0]); originalArray[i] = i*i + 1;
x=y; } modifyArray(arr, len); }
processArray(originalArray, 5);
void display() { std::cout << "Modified Array: "; for (int i = 0; i < 5; ++i) {
cout<<x; } for (int i=0; i<len; i++) std::cout << originalArray[i]
}; std::cout << arr[i] << " "; << " ";
}
int main() { return 0;} delete[] originalArray;
Number Obj1;
Obj1.display(); return 0;
return(0); } }
Solution 4:
Marking Strategy
1 Marks for Output
1 Mark for correct explanation
a) b) c)