Posts

Showing posts from June, 2020

Program to find the Area of a Rectangle using Class in C++

# Program to find the Area of a Rectangle using Class in C++: To create a program for the area of a rectangle. We have to create a Rectangle class, In which we will have to private member variables of integer type like iHeight and iWidth for storing the height and width of the rectangle, then we have to create one member function to calculate the area of the rectangle. Then in the main function, we create one object of Rectangle class and provide height and width of the rectangle then call the function area to know the area of that rectangle and then we print it using cout. # include < iostream > using namespace std ; class Rectangle { int iHeight ; int iWidth ; public : Rectangle () { } Rectangle ( int height , int width ) : iHeight ( height ), iWidth ( width ) { } int area () { int iArea ; iArea = iHeight * iWidth ; return iArea ; } }; int main () { Rectangle ...

Print a const string in c

Print a const string in c We can print a const string in c like below: printf ( "Hello World" ); or const char string [] = "Hello World!" ; printf ( "%s" , string );

Convert std::string to C String

# Convert std::string to C String To convert an std::string to C string we have to use the method  c_str()  like below: std :: string str = "string" ; const char * cstr = str . c_str (); For more info you can follow this link .