teratail header banner
teratail header banner
質問するログイン新規登録
C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

2回答

415閲覧

C言語、文章内での文字数のカウント

Riko12

総合スコア0

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2022/05/04 04:30

0

0

学校の課題で、文章内での文字数の数え方を作るC言語のプログラミングが全くわかりません。全くのプログラミング初心者です。助けてください

(文章)
You can sit before the desk (or in front of the desk). The professor can sit on
the desk (when he's being informal) or behind the desk, and then his feet are
under the desk or beneath the desk. He can stand beside the desk (meaning next
to the desk), before the desk, between the desk and you, or even on the desk (if
he's really strange). If he's clumsy, he can bump into the desk or try to walk
through the desk (and stuff would fall off the desk). Passing his hands over the
desk or resting his elbows upon the desk, he often looks across the desk and
speaks of the desk or concerning the desk as if there were nothing else like the
desk. Because he thinks of nothing except the desk, sometimes you wonder about
the desk, what's in the desk, what he paid for the desk, and if he could live
without the desk. You can walk toward the desk, to the desk, around the desk, by
the desk, and even past the desk while he sits at the desk or leans against the
desk.

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

SaitoAtsushi

2022/05/04 04:54

「全くわからない」というのは要するに入門書の頭から全部解説する必要があるという意味ですのでここで回答するのは非現実的です。 質問は具体的であることが望ましく、より良い質問の作法は以下の URL にまとめられていますので、まずは一読することをお勧めします。 https://teratail.com/help/question-tips
BeatStar

2022/05/04 06:19

答えではなくヒントのヒントでもいいのなら質問本文を編集してください。今のままだと丸投げにしか見えません。質問は編集できるので編集しましょう。
episteme

2022/05/04 06:29

あらら、C++じゃないのか...なら僕の回答はスルーしてください。
thkana

2022/05/04 13:15

課題を課せられるということはそれまでの授業を受けているはずで「全くのプログラミング初心者」のはずはない、と思うのですがいかがですか?
guest

回答2

0

残念ながら、ここではコードの作成依頼は受け付けていません

まずはあなたなりにコードを書いてみましょう。その上でわからないことを聞いていただければお答えできるかと思います。

投稿2022/05/04 05:09

y_waiwai

総合スコア88180

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

コレ↓を提出したら解説を求められるだろうからうまく答えてね。

C++

1#include <iostream> 2#include <string> 3#include <algorithm> 4#include <cctype> 5 6int main() { 7 std::string str = 8R"_(You can sit before the desk (or in front of the desk). The professor can sit on 9the desk (when he's being informal) or behind the desk, and then his feet are 10under the desk or beneath the desk. He can stand beside the desk (meaning next 11to the desk), before the desk, between the desk and you, or even on the desk (if 12he's really strange). If he's clumsy, he can bump into the desk or try to walk 13through the desk (and stuff would fall off the desk). Passing his hands over the 14desk or resting his elbows upon the desk, he often looks across the desk and 15speaks of the desk or concerning the desk as if there were nothing else like the 16desk. Because he thinks of nothing except the desk, sometimes you wonder about 17the desk, what's in the desk, what he paid for the desk, and if he could live 18without the desk. You can walk toward the desk, to the desk, around the desk, by 19the desk, and even past the desk while he sits at the desk or leans against the 20desk.)_"; 21 22 // alphabet(a-z, A-Z) を勘定する 23 std::cout << std::count_if(str.begin(), str.end(), [](char ch) { return std::isalpha(ch);}) << std::endl; 24}

[追記] C版

C

1#include <stdio.h> 2#include <ctype.h> 3 4int main() { 5 const char* str = 6"You can sit before the desk (or in front of the desk). The professor can sit on " 7"the desk (when he's being informal) or behind the desk, and then his feet are " 8"under the desk or beneath the desk. He can stand beside the desk (meaning next " 9"to the desk), before the desk, between the desk and you, or even on the desk (if " 10"he's really strange). If he's clumsy, he can bump into the desk or try to walk " 11"through the desk (and stuff would fall off the desk). Passing his hands over the " 12"desk or resting his elbows upon the desk, he often looks across the desk and " 13"speaks of the desk or concerning the desk as if there were nothing else like the " 14"desk. Because he thinks of nothing except the desk, sometimes you wonder about " 15"the desk, what's in the desk, what he paid for the desk, and if he could live " 16"without the desk. You can walk toward the desk, to the desk, around the desk, by " 17"the desk, and even past the desk while he sits at the desk or leans against the " 18"desk."; 19 20 int count = 0; 21 while ( *str ) if ( isalpha(*str++) ) ++count; 22 printf("%d alphabets.\n", count); 23 return 0; 24}

投稿2022/05/04 06:23

編集2022/05/04 06:37
episteme

総合スコア16612

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.30%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問