Write a program in C++ that defines a class named StringOps. Declare data members of
this class as described below:
ï‚· variable str of data type string.
ï‚· variable size of data type integer which represents the length of the string str.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
class StringOps {
private:
string str;
int size ;
public:
StringOps(string str, int size ) {
this->str = str;
this->size = size;
}
void print(){
cout<<"String: "<<str<<"\n";
cout<<"Size: "<<size<<"\n";
}
~StringOps(){
}
};
int main(void){
StringOps str("String",6);
str.print();
cout<<"\n\n";
system("pause");
return 0;
}
Comments
Leave a comment