Friday, 7 August 2015

Write a code that takes the input by the user. Then count the total number of spaces in that string.

Leave a Comment
#include<iostream>
#define size 100
using namespace std;
class String_Data{
public:
String_Data(int,int,int,char *);//parameterized constructor
String_Data(String_Data&); //copy constructor
~String_Data();
void menupulateString(const char*);
int getSpace();
int getLength();
int getWovel();
private:
char *str;
int wovel,consonents,length,spaces;
};

String_Data::String_Data(int wovel=0,int length=0,int spaces=0,char *str=NULL)
{
if(str!=NULL)
{
this->str=new char[strlen(str)+1];
}
this->consonents=consonents;
this->spaces=spaces;
this->length=length;
this->wovel=wovel;
}
String_Data::String_Data(String_Data &obj)
{
if(str!=NULL)
{
this->str=new char[strlen(obj.str)+1];
}
this->consonents=obj.consonents;
this->spaces=obj.spaces;
this->length=obj.length;
this->wovel=obj.wovel;
}
String_Data::~String_Data()
{
delete []str;
}
void String_Data::menupulateString(const char*p){

int wovel=0,length=0,spaces=0;
for (int i=0;p[i]!='\0';i++)
{
if(p[i]==' ')
{
spaces++;
}
if(p[i]=='a'||p[i]=='A'||p[i]=='e'||p[i]=='E'||p[i]=='i'||p[i]=='I'||p[i]=='o'||p[i]=='O'||p[i]=='u'||p[i]=='U'||)
{
wovel++;
}
length++;
}
this->length=length;
this->spaces=spaces;
this->wovel=wovel;
}
int String_Data::getLength{
return length;
}




int String_Space_counter(char *);
void main()
{
int str;
char *string=new char [size]+1;
gets(string);
str=String_Space_counter(string);
cout<<"Total Spaces in string = "<<str;
}

int String_Space_counter(char *p)
{

return temp;
}
If You Enjoyed This, Take 5 Seconds To Share It

0 Questions: