Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me urgently in C++ Question 1: Define a class called v which has the

ID: 3680914 • Letter: P

Question

Please help me urgently in C++

Question 1: Define a class called v which has the private data members length (oftype int), norm2 (of type float), and p a pointer (of type float). The class also has the member functions set(int), print0, gerNorm20, culate Norm20, a default parameterized constructor, and a destructor. Implement member functions. Use the following drive int main0 vector u: int ulength; cout Enter the vector length cin uLength: u set(uLength); u, print(); retum 0 Sample input output Enter the vector length 5 Enter 5 vector elements 4 7 9 2 8 The vector [4, 7, 9, 2, 8] has the norm 14.6287 Question 2: Add a destructor to the class and add the following code to the end of the above driver: vector v(u); print(); Sample input/output: Enter the vector length 5 Enter 5 vector elements 4 7 9 2 8 The vector [4, 7, 9, 2, 8] has the norm: 14.6287 The vector [4, 7, 9, 2, 8) has the norm: 14.6287 the 14.6287 The vector (7.17e 19e-e39 16887 e-039 9, 2, 81 has norm Question 3: Add a copy constructor to the class. Sample input output Enter the vector length: 5 Enter 5 vector elements 4 7 9 2 8 14.6287 The vector [4 7, 9, 2, 8) has the norm The vector [4 7, 9, 2, 8) has the norm: 14.6287 The vector [4, 7, 9, 2, 8] has the norm: 14.6287

Explanation / Answer

#include <iostream>
#include <math.h>
using namespace std;
class vector{
private:
int length;
float *p;
float norm2;
int a[100];
public:
vector(int len)
{
length=len;
cout << " Enter " << length << " vector elements ";
}


void print()
{
int i;
cout << " The vector [";
for(i=0;i<length-1;i++)
{
cout <<a[i]<<",";
}
cout <<a[length-1]<<"] has the norm : " <<calculateNorm2()<<" ";

}
int set(int uLength)
{
int i;
length=uLength;

for(i=0;i<length;i++)
{
cin >> a[i];
}

return length;
}
float calculateNorm2()
{
int sum=getNorm2();
return (sqrt(sum));
}
int getNorm2()
{
int i,j,sum=0;
for(i=0;i<length;i++)
{
sum=sum+(a[i]*a[i]);
}
return sum;

}

};

int main()
{

int uLength;
cout << "Enter the vector length :";
cin >> uLength;
vector u(uLength);
u.set(uLength);
u.print();
{
vector v(u);
v.print();
}
u.print();
return 0;
}