Please help.


I need someone to help me with this homework problem.

I need to write a program that tells the user to enter a string that includes a combination of letters
(uppercase or lower), digits, spaces, punctuation marks and/or any other keyboard symbols.

Thank you if you help me and I would appreciate it.

I don't get what you're trying to do. You want the computer to ask the user for a string input (allowing the user to enter every character?)
If that's the case, here you are:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "stdafx.h"
#include <iostream>
#include <string>

int main()
{
	std::cout << "Please enter something: \n";
	std::string string;  // to get a string   
	getline(std::cin, string);  // getline to read every character (input)
	std::cout << "You entered: " << string << std::endl;

    return 0;
}
Last edited on
Thank you very much for responding, but here is what I need to do:

// Return the true if a character is one of the following punctuation marks: ,.?;:”’{}[] /
bool isPunctuationMark(char c)
// Return the true if a character is a vowel (a, e, i, o, or u) or (A, E, I, O, or U)
bool isVowel(char c)
// Return the reversed string of a string
string reverseString(string i)

Here is the following code:

#include <iostream>
#include <string>

using namespace std;

bool isVowel(char c)
{

}

bool isPunctuationMark(char c)
{

}
int main()
{
// program need to read in a string (including spaces);

// show a reverse string

return 0;

}
closed account (48T7M4Gy)
OK so that looks like the template your were given. So what have you added to it, for example what have you written for reading in a string with spaces? Hint: check getline function
Nothing I just wrote a

string reverseString(string i)

to give me the reverse string of a string
closed account (48T7M4Gy)
Well, I think you need to take the advice you have already been given - twice now. Break the problem down into steps and do the first step of reading in the string and printing it out.

If you can't do that then I'd suggest you read your notes and textbook and don't even consider going onto the reverse string part, especially because there are other parts preceding it. Maybe you should have a talk with your teacher/tutor too and get some guidance.

Given your questions on other problems here you have posted you also need to be clear that this is not a homework site. If you make some effort to attempt the problem solutions yourself then you'll find that plenty of help is available. The reverse is not so productive for you. :)
Yes thank you I just wanted to be clear on what to do but now it is my turn.
Here are the component parts, try putting them together in a complete program:

- for vowel:
1
2
string s;
s.find_first_of("AEIOUaeiou");


- for punctuation:
ispunct() : http://www.cplusplus.com/reference/cctype/ispunct/

- to reverse string: http://www.cplusplus.com/reference/algorithm/reverse/
Thank you gunnerfunner.
closed account (48T7M4Gy)
What about thanking Tony1998 too?
Oh sorry thank you Tony1998, kemort and gunnerfunner.
So now I am stuck on getting the uppercase and lowercase letters to be counted of the string I entered.

#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <stdio.h>
#include <cctype>
using namespace std;

bool isVowel(char c)
{
switch(c)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
return true; break;
default:
return false;
}
}

bool isPunctuationMark(char c)
{
const string punct = "+=%₩<>!@#~/^&*()-\'\":;,\?`_\\|{}[]$€£¥";
return punct.find(c);
}
int main()
{
//char str[100];

string line;
int vowels, consonants, digits, spaces, upper, lower;

vowels = consonants = digits = spaces = upper = lower = 0;

cout << "Enter a string: ";
getline(cin, line);

for(int i = 0; i < line.length(); ++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
line[i]=='o' || line[i]=='u' || line[i]=='A' ||
line[i]=='E' || line[i]=='I' || line[i]=='O' ||
line[i]=='U')
{
++vowels;
}
else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
{
++consonants;
}
else if(line[i]>='0' && line[i]<='9')
{
++digits;
}
else if (line[i]==' ')
{
++spaces;
}
else if (line[i] >= 'A' && line[i] <= 'Z')
{
++upper;
}
else if (line[i] >= 'a' && line[i] <= 'z')
{
++lower;
}
}

cout<< " " << endl;
cout << "Total count of letter<s> is" << " with " << endl;
cout << setw(8) << upper << " upper case letter<s>" << endl;
cout << setw(8) << lower << " lower case letter<s>" << endl;
cout << setw(8) << vowels << " vowel<s>" << endl;
cout << setw(8) << consonants << " consonant<s> " << endl;
cout << " " << endl;
cout << "Total count of digit<s> is " << digits << endl;
cout << " " << endl;
cout << "Total count of punctuation marks<s> is " << isPunctuationMark << endl;
cout << " " << endl;
cout << "Total count of whitespace<s> is " << spaces << endl;
cout << " " << endl;
cout << "The reverse string: ";
return 0;

}
Here you go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
std::string reverse(const std::string &s)
{
    return std::string(s.crbegin(), s.crend());
}

bool isVowel(char c)
{
    const std::string vowels = "aAeEiIoOuU";
    return vowels.find(c) != std::string::npos;
}

bool isPunct(char c)
{
    const std::string punct = "+=%₩<>!@#~/^&*()-\'\":;,\?`_\\|{}[]$€£¥";
    return punct.find(c) != std::string::npos;
}
Thanks boost lexical cast I will try it out. Appreciate it the help.
Topic archived. No new replies allowed.