Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,490 members, 7,819,781 topics. Date: Monday, 06 May 2024 at 11:10 PM

Help Me With The Solution To This Problem In C++ - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Me With The Solution To This Problem In C++ (924 Views)

An INEC Voting Console Program Written In C Language / Please Help Me Solve This Problem In C++ / Who Can Solve This Problem Using Java (2) (3) (4)

(1) (Reply) (Go Down)

Help Me With The Solution To This Problem In C++ by clockwisereport: 8:02am On Sep 03, 2019
Can you please help me rewrite this code using while loop and traditional for loop

#include <iostream>
#include <string>
Using namespace std;

void changeToX ( )
{
string s;
//prompt the user to enter the string
cout<<"Enter the string you would like to change to X"<<endl;
getline (cin, s);
for (char &c : s)
c = 'X';
cout <<s <<endl;
}

int main ( )
{
changeToX ( );
}

@lordZouga, @whizTim @kudaisi @segbolon
Re: Help Me With The Solution To This Problem In C++ by clockwisereport: 8:03am On Sep 03, 2019
Again, help me with the solution to this problem

Write a program that reads a string of characters including punctuation and writes what was read but with the punctuation removed.
Thank you
Re: Help Me With The Solution To This Problem In C++ by codekobo: 8:11am On Sep 03, 2019
// CPP program to remove punctuation from a given string


#include <iostream>

using namespace std;



int main()
{

// input string

std::string str = "Welcome@@##$ to#$% Code%$^Kobo$%^&.COM";



for (int i = 0, len = str.size(); i < len; i++)

{

// check whether parsing character is punctuation or not

if (ispunct(str[i]))

{

str.erase(i--, 1);

len = str.size();

}

}



// print string without punctuation

std::cout << str;

return 0;
}


Be sure to join the new platform for developers https://codekobo.com and consider using the discussion forums https://codekobo.com next time which has better features for developers like syntax highlighting

2 Likes

Re: Help Me With The Solution To This Problem In C++ by clockwisereport: 9:09am On Sep 03, 2019
Thanks @codekobo. Chukwu gozie gi
Re: Help Me With The Solution To This Problem In C++ by fr3do(m): 7:59am On Sep 04, 2019
I think not sure, if a method is going to ask for input, as in 'Cin', then the method name should reflect that input as in ' changeToX(String S)'.

(1) (Reply)

Afri-tech United Is Looking For A Lead Architech / Application close 30th may, 2020: Junior Website Designer Needed Urgently / Which Server Is The Best For A Website With 200,000 Active Users?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.