question

write c++ program that read a positive integer number x from keyboard and read a number of alphabet characters equals to (x) from keyboard . after that check an count the number of vowels alphabet and the number of non-vowel alphabet characters?
To get you started:
1
2
3
4
5
// read positive int
	int num{0};
	std::cout << "Enter a positive number: ";
	std::cin >> num;
	//check if num is greater than 0... 
Last edited on
I want complete program
closed account (z05DSL3A)
Alaa Najjar wrote:
I want complete program

You had best get writing some code then.
I'm feeling generous. Here's a complete program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iomanip>
#include <iostream>
#include <string>

struct letter_stats
{
    letter_stats(const std::string& letters);

    friend std::ostream& operator<<(std::ostream& os, const letter_stats& ls)
    {
        os << "Vowels: " << ls._vowels;
        return os << ", Non-vowels: " << ls._processed - ls._vowels;
    }

private:
    unsigned _processed;
    unsigned _vowels;
};

letter_stats::letter_stats(const std::string& letters) 
    : _processed(), _vowels()
{
    const std::string vowels = "aeiouAEIOU";

    for (auto letter : letters)
        if (++_processed, std::string::npos == vowels.find(letter))
            ++_vowels;
}

int main()
{
    unsigned val;
    std::cin >> val;

    std::string input;
    std::cin >> std::setw(val) >> input;

    if (val != input.size())
        std::cout << "You didn't enter enough alphabets or"
                     " maybe it wasn't all alphabets!\n";
    else
        std::cout << letter_stats(input) << '\n';
}


I'm pretty sure it has a couple bugs in it, though. Good luck working it out!
I want that beginning:
#include<iostream>
using namespace std;
int main ()
I want that beginning:
#include<iostream>
using namespace std;
int main ()

Of course. I wouldn't want to put you out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
using namespace std;

int main()
{
    void do_work();
    do_work();
}

#include <iomanip>
#include <string>

struct letter_stats
{
    letter_stats(const std::string& letters);

    friend std::ostream& operator<<(std::ostream& os, const letter_stats& ls)
    {
        os << "Vowels: " << ls._vowels;
        return os << ", Non-vowels: " << ls._processed - ls._vowels;
    }

private:
    unsigned _processed;
    unsigned _vowels;
};

letter_stats::letter_stats(const std::string& letters)
    : _processed(), _vowels()
{
    const std::string vowels = "aeiouAEIOU";

    for (auto letter : letters)
        if (++_processed, std::string::npos == vowels.find(letter))
            ++_vowels;
}

void do_work()
{
    unsigned val;
    std::cin >> val;

    std::string input;
    std::cin >> std::setw(val) >> input;

    if (val = input.size())
        std::cout << "You didn't enter enough alphabets or"
        " maybe it wasn't all alphabets!\n";
    else
        std::cout << letter_stats(input) << '\n';
}


I'm pretty sure it still has a couple bugs in it. Good luck working it out!
Wouldn't you think he would learn a tiny bit more when he writes the progarm himself?
Wouldn't you think he would learn a tiny bit more when he writes the progarm himself?

A) He can't use this, because it would be rather clear to whomever is grading it that he didn't generate it.
B) It doesn't actually work.
C) He doesn't have the technical savvy to debug it.

So as I see it, if he tries to debug it, he exposes himself to language elements he hasn't encountered yet which I'll take as a win, and if he doesn't - nothing lost.

If he actually turns it in as-is I suppose he'll probably get what he deserves. ;)
Good points, thanks for clearing that up :)
this is my first and last class in c++, I study biology, I didn't take most of these things. I wrote half program, I need help to complete it

#incllude <iostream>
using namespace std;
int main()
{
int counter = 0;
char x;


while (counter <= 10)
{cout<<"enter "<<" letter \n";
cin>>x;

counter++;

}

Last edited on
To help you get started:


write c++ program that read a positive integer number x from keyboard


1
2
3
int counter = 0;
cout << "Enter number of characters: ";
cin >> counter;


Once you know how many characters the program will get you can use a loop for the input.
read a number of alphabet characters equals to (x) from keyboard
1
2
3
4
5
6
7
8
char ch;
for (int i=0; i < counter; i++)
{
  cout << " \nEnter character #" << i << " ";
  cin >> ch;
 class="quote">
class="qd"> count the number of vowels alphabet and the number of non-vowel alphabet characters
// process your character }



and read a number of alphabet characters equals to (x) from keyboard . after that check an count the number of vowels alphabet and the number of non-vowel alphabet characters?
Is there any wisdom/reason behind using the underscore before the variable name? Is their a standard notation behind it?
Is there any wisdom/reason behind using the underscore before the variable name? Is their a standard notation behind it?


I think it's just to denote that the variable is a member of a class.
Last edited on
Topic archived. No new replies allowed.