5- Write a program that implements the equivalent functionality of strlen. This function takes a pointer to a char and determines the length of the array.
I want part 5 in the image plz
please give me the full final code not ex5 only
check if it contains something wrong
this is the soution for the first 4
#include <iostream>
#include <algorithm>
using namespace std;
// Global constant variable
const int PI = 3.1415;
// Cylinder class definition
class cylinder{
// Private member variables
private:
double radius,height,diameter;
static int count;
public:
// Default constructor
cylinder(){
radius = 1;
height = 1;
count=count+1;
}
// Parametrized constructor to check that the
// variable is positive and less than 20, otherwise
// variable will be assigned its default value of 1.
cylinder(double r,double h){
if(r>0 && r<=20)
radius = r;
else
radius = 1;
if(h>0 && h<=20)
height = h;
else
height = 1;
count=count+1;
}
cylinder(const cylinder &c)
{
radius=c.radius;
height=c.height;
diameter=c.diameter;
}
// A reader for radius variable
double getRadius(){
return radius;
}
// A reader for height variable
double getHeight(){
return height;
}
// A writer for radius variable
void setRadius(double r){
radius = r;
}
// A writer for height variable
void setHeight(double h){
height = h;
}
// A reader for diameter
double getDiameter(){
return diameter;
}
// A writer for daimeter
void setDiameter(double d){
diameter = d;
}
int getCount(){
return count;
}
// A member function “volume” which
// calculates the volume of a cylinder.
double volume(){
return PI*radius*radius*height;
}
// A member function “print” which prints
// the radius, diameter, and height of a cylinder.
void print(){
cout<<"\nRadius = "<<radius;
cout<<"\nDiameter = "<<diameter;
cout<<"\nHeight = "<<height;
}
// A member function display_name() which displays “cylinder
void display_name(){
cout<<"\nCylinder volume = "<<this->volume();
}
~cylinder()
{
count=0;
}
};
int cylinder::count=0;
bool sort_by_height(cylinder* c1, cylinder *c2)
{
return (c1->getHeight()<c2->getHeight());
}
// Driver Program
int main()
{
int radius,height;
cylinder arr[5];
for (int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++)
{
cout<<"Enter radius: ";
cin>>radius;
cout<<"Enter height: ";
cin>>height;
cylinder c(radius,height);
//storing the value of radius in the array
arr[i]=c;
}
cylinder *head[5];
head[0]=&arr[0];
head[1]=&arr[1];
head[2]=&arr[2];
head[3]=&arr[3];
head[4]=&arr[4];
sort(head, head+5, sort_by_height);
cout<<"Cylinders sorted in ascending order of height"<<endl;
for(int i=0;i<5;i++)
{
cout<<head[i]->getHeight()<<" ";
}
return 0;
}
Step by step
Solved in 2 steps with 3 images