0% found this document useful (0 votes)
10 views8 pages

T1 Paper With Solution Even 2024

The document outlines three C++ programming tasks involving classes for calculating employee tax, determining the final position of a boat in 2D space, and creating feasible products based on cost and selling price. Each task includes a detailed description, marking strategy, and sample code implementations. Additionally, it provides a fourth task analyzing code snippets with expected outputs and explanations.

Uploaded by

Kush Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views8 pages

T1 Paper With Solution Even 2024

The document outlines three C++ programming tasks involving classes for calculating employee tax, determining the final position of a boat in 2D space, and creating feasible products based on cost and selling price. Each task includes a detailed description, marking strategy, and sample code implementations. Additionally, it provides a fourth task analyzing code snippets with expected outputs and explanations.

Uploaded by

Kush Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Solution T1 paper

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

Enter Tax Deductibles… Enter Tax Deductibles… Enter Tax Deductibles…


eid: 123 eid: 100 eid: 324
insurancePremium: 40000 insurancePremium: 70000 insuarancePremium: 40000
homeLoanInterest: 160000 homeLoanInterest: 250000 homeLoanInterest: 160000

Your total deduction = Your total deduction = Sorry!! unable to compute


40000+160000 = 200000. 50000+250000 = 300000. tax as the eid don’t match.

You Annual Tax = 10% of You Annual Tax = 10% of


(1000000 - 200000) = 80000. (1500000 – 300000) =
120000.

Solution1
Marking Strategy

1 Marks for each case given in the question 3*1=3


0.5 for Forward declaration
1 Marks for bot class declaration and definitions
0.5 for friend function (calling and declaration)

#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;
}

friend void computeTax(Employee E, TaxDeductibles T);


};

void computeTax(Employee E, TaxDeductibles T)


{
double totalDeduction, insuPrem;
if(E.eid != T.eid)
{
cout<<"sorry!! unable to compute tax as eid don't match. "<<endl;
}
else
{
if(T.insuarancePrem > 50000)
{
insuPrem = 50000;
}
else
{
insuPrem = T.insuarancePrem;
}
totalDeduction = insuPrem + T.homeLoanInt;
cout<<"\nYour total deduction = \n"<<insuPrem<<" +
"<<T.homeLoanInt<<" = "<<totalDeduction<<endl;
cout<<"Your annual tax = 10% of ("<<E.annualSalary<<" -
"<<totalDeduction<<") = "<<0.1*(E.annualSalary-totalDeduction)<<endl;
}
return;
}

int main(void)
{
Employee E;
TaxDeductibles T;
E.setEmployee();
T.setDeductibles();
computeTax(E,T);
return 0;
}

2. [CO2] [Marks 4] The position of an object in two-dimensional space in vector


notation is represented as P = ax + by while the velocity of the object is represented as
V = v1x + v2y. Assuming that the initial position of a boat in a lake to be (ax + by) m
from its starting point and its velocity to be (v1x + v2y) m/s, the final position of the
boat after t secs (t is a scalar) can be computed as (ax + by) + (v1x + v2y)*t from its
starting position. Design a class whose objects can store the position and velocity of an
object in 2D space in the given format and overload the + and * operator to get the final
position. The initial position, velocity and the time interval must be entered by the user.
Solution 2

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 Product :: count = 0;

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)

ERROR! Modified Array: 10 25 30 65 4 8 20 40 68


error: call of overloaded 50
'Number()' is ambiguous
19 | Number Obj1; This code is executing on all clang
| ^~~~ compilers and programiz.com.
Many other online compilers and
'Number::Number(int)' gcc /g++ (newer versions)
compiler are not able to execute
11 | Number (int y=5) {
this code due to added protection
| ^~~~~~ flag. It can be executed by using
flag -fno-stack-protector i.e.
'Number::Number()' disabling the protection. So, we
8 | Number (){ can consider the Error: ***
| ^~~~~~ stack smashing
detected *** as correct
answer. The reason is
incrementing the pointer (arr++)
beyond the size of the array.

You might also like