I dont understand why the if(ispunct(s.at(k))) then tolower function is not work
ID: 3762635 • Letter: I
Question
I dont understand why the if(ispunct(s.at(k))) then tolower function is not working on my code, i need the program to stop captalizing after the "." puntion. For example : Input : My favorite sport is baseball. My favorite team is the yankees Output: My FAVORITE sport IS baseball. My favorite team is the yankees.
#include
#include
using namespace std;
int main()
{
string s;
int i=0;
int j=0;
int k=-1;
cout<< "Type a sentece: ";
getline (cin, s);
for (i=0; i<=s.length(); i++){
for (j=k+1; j< s.length() && isspace(s.at(j))==false; j++){
if(ispunct(s.at(j)))
break;
else
cout<< s[j];
}
cout<<' ';
for (k=j+1; k < s.length() && isspace(s.at(k))==false; k++){
if(ispunct(s.at(k)))
break;
else
s[k] = toupper(s.at(k));
cout<< s[k];
}
cout<<' ';
}
return 0;
}
Explanation / Answer
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rno,m1,m2;
public:
void get()
{
cout<<"Enter the Roll no :";
cin>>rno;
cout<<"Enter the two marks :";
cin>>m1>>m2;
}
};
class sports
{
protected:
int sm; // sm = Sports mark
public:
void getsm()
{
cout<<" Enter the sports mark :";
cin>>sm;
}
};
class statement:public student,public sports
{
int tot,avg;
public:
void display()
{
tot=(m1+m2+sm);
avg=tot/3;
cout<<" Roll No : "<<rno<<" Total : "<<tot;
cout<<" Average : "<<avg;
}
};
void main()
{
clrscr();
statement obj;
obj.get();
obj.getsm();
obj.display();
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.