Q5: a- create a class with four integer member variables x, y, z and w; it also has the following member functions: parameterized constructor to set the values of the private variables. friend function to calculate and return the value of p as follows: (5x + y – z)3 хуz |x – y| if 1

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

write in c++

Q5: a- create a class with four integer member variables x, y, z and w; it also has the following member
functions:
parameterized constructor to set the values of the private variables.
friend function to calculate and return the value of p as follows:
(5x + y - z)3
if 1<w< 5
if6 <w < 10
Vxyz
|x – yl
p =
otherwise
Transcribed Image Text:Q5: a- create a class with four integer member variables x, y, z and w; it also has the following member functions: parameterized constructor to set the values of the private variables. friend function to calculate and return the value of p as follows: (5x + y - z)3 if 1<w< 5 if6 <w < 10 Vxyz |x – yl p = otherwise
Expert Solution
Step 1)Code is Given Below

#include <iostream>
#include<cmath>
using namespace std;
//creating class
class Calculate{
    //declaring private variables
    private:
        int x;
        int y;
        int z;
        int w;
    public:
    //create constructor and set values
        Calculate(int a,int b,int c,int d){
            x=a;
            y=b;
            z=c;
            w=d;
        }
        //creating friend function
        friend float calculateP(Calculate &c);
};
//define function
float calculateP(Calculate &c){
    float p;
    //check if w in range [1-5]
    if(c.w>=1 && c.w<=5){
        //if yes find its value
        p=(5*(c.x)+c.y-c.z);
        p=p*p*p;
    }
    //check if w in range [6-10]
    else if(c.w>=6 && c.w<=10){
        //if yes find its value
        p=sqrt(c.x*c.y*c.z);
    }
    //other wise calculate default value
    else{
        p=abs(c.x-c.y)/(float)c.z;
    }
    return p;
}
int main()
{
    //create 3 calculate object
    Calculate c1(1,2,3,4);
    Calculate c2(2,3,4,6);
    Calculate c3(2,3,4,11);
    // call function and print result
    cout<<"Value of p : "<<calculateP(c1)<<"\n";
    cout<<"Value of p : "<<calculateP(c2)<<"\n";
    cout<<"Value of p : "<<calculateP(c3)<<"\n";
   
   return 0;
}

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY