본문내용
i] <= \'Z\'))
cnt_al++;
else if(text[i] >= \'1\' && text[i] <= \'9\')
cnt_num++;
else if(text[i] == \' \')
cnt_bl++;
}
cout<<\"알파벳 글자의 갯수는 : \"<
cout<<\"숫자의 갯수는 : \"<
cout<<\"공백 문자의 갯수는 : \"<
return 0;
}
9. 사용자로부터 문자열을 받아서 단어의 개수를 계산하여서 콘솔에 출력하는 프로그램을 작성하여 보자.
#include
#include
using namespace std;
int main()
{
int cnt_word = 1;
string text;
cout<<\"문자열을 입력하세요 : \";
getline(cin, text);
for(int i = 0; i < text.length(); i++)
{
if (text[i] == \' \'){
cnt_word++;
}
}
cout<<\"단어의 개수는 : \"<
return 0;
}
10. 사용자에게서 받은 문자열을 역순으로 화면에 출력하는 프로그램을 작성하여 보자.
#include
#include
using namespace std;
int main()
{
int i;
string str;
cout<<\"문자열을 입력하세요 : \";
getline(cin, str);
for(i = str.length() -1; i >= 0; i--)
cout<
cout<
return 0;
}
11. 사용자로부터 받은 문자열에서 자음과 모음의 개수를 계산하여서 출력하는 프로그램을 작성하라.
#include
#include
using namespace std;
int main()
{
int cnt_vowel = 0, cnt_con = 0;
string text;
cout<<\"문자열을 입력하세요 : \";
getline(cin, text);
for(int i=0; i < text.length(); i++)
{
if ((text[i] >= \'a\' && text[i] <= \'z\') || (text[i] >= \'A\' && text[i] <= \'Z\')){
if(text[i] == \'a\' || text[i] == \'e\' || text[i] == \'i\' || text[i] == \'o\' || text[i] == \'u\' ){
cnt_vowel++;
}
else{
cnt_con++;
}
}
}
cout<<\"자음의 개수는 : \"<
cout<<\"모음의 개수는 : \"<
return 0;
}
12. 사용자로부터 아이디와 패스워드를 받아서 일치하는지를 검사하는 프로그램을 작성하여 보자.
#include
#include
using namespace std;
int main()
{
string id(\"HONG\");
string pwd(\"1234\");
string u_id, u_pwd;
cout<<\" > ID를 입력하세요 : \";
cin>>u_id;
cout<<\" > 패스워드를 입력하세요 : \";
cin>>u_pwd;
if( id == u_id && pwd == u_pwd)
cout<<\" >> ID, 패스워드가 일치합니다. \"<
else
cout<<\" >> ID, 패스워드가 일치하지 않습니다. \"<
return 0;
}
13. 워드 프로세서에 사용되는 “찾아 바꾸기” 기능을 구현하여 보자.
#include
#include
using namespace std;
int main()
{
int cnt_vowel = 0, cnt_con = 0;
string text, search_text, change_text;
cout<<\"문자열을 입력하세요 : \";
getline(cin, text);
cout<<\"찾을 문자열을 입력하세요 : \";
cin>>search_text;
cout<<\"바꿀 문자열을 입력하세요 : \";
cin>>change_text;
text.replace(text.find(search_text),change_text.length(),change_text);
cout<
return 0;
}
cnt_al++;
else if(text[i] >= \'1\' && text[i] <= \'9\')
cnt_num++;
else if(text[i] == \' \')
cnt_bl++;
}
cout<<\"알파벳 글자의 갯수는 : \"<
}
9. 사용자로부터 문자열을 받아서 단어의 개수를 계산하여서 콘솔에 출력하는 프로그램을 작성하여 보자.
#include
#include
using namespace std;
int main()
{
int cnt_word = 1;
string text;
cout<<\"문자열을 입력하세요 : \";
getline(cin, text);
for(int i = 0; i < text.length(); i++)
{
if (text[i] == \' \'){
cnt_word++;
}
}
cout<<\"단어의 개수는 : \"<
}
10. 사용자에게서 받은 문자열을 역순으로 화면에 출력하는 프로그램을 작성하여 보자.
#include
#include
using namespace std;
int main()
{
int i;
string str;
cout<<\"문자열을 입력하세요 : \";
getline(cin, str);
for(i = str.length() -1; i >= 0; i--)
cout<
}
11. 사용자로부터 받은 문자열에서 자음과 모음의 개수를 계산하여서 출력하는 프로그램을 작성하라.
#include
#include
using namespace std;
int main()
{
int cnt_vowel = 0, cnt_con = 0;
string text;
cout<<\"문자열을 입력하세요 : \";
getline(cin, text);
for(int i=0; i < text.length(); i++)
{
if ((text[i] >= \'a\' && text[i] <= \'z\') || (text[i] >= \'A\' && text[i] <= \'Z\')){
if(text[i] == \'a\' || text[i] == \'e\' || text[i] == \'i\' || text[i] == \'o\' || text[i] == \'u\' ){
cnt_vowel++;
}
else{
cnt_con++;
}
}
}
cout<<\"자음의 개수는 : \"<
}
12. 사용자로부터 아이디와 패스워드를 받아서 일치하는지를 검사하는 프로그램을 작성하여 보자.
#include
#include
using namespace std;
int main()
{
string id(\"HONG\");
string pwd(\"1234\");
string u_id, u_pwd;
cout<<\" > ID를 입력하세요 : \";
cin>>u_id;
cout<<\" > 패스워드를 입력하세요 : \";
cin>>u_pwd;
if( id == u_id && pwd == u_pwd)
cout<<\" >> ID, 패스워드가 일치합니다. \"<
cout<<\" >> ID, 패스워드가 일치하지 않습니다. \"<
}
13. 워드 프로세서에 사용되는 “찾아 바꾸기” 기능을 구현하여 보자.
#include
#include
using namespace std;
int main()
{
int cnt_vowel = 0, cnt_con = 0;
string text, search_text, change_text;
cout<<\"문자열을 입력하세요 : \";
getline(cin, text);
cout<<\"찾을 문자열을 입력하세요 : \";
cin>>search_text;
cout<<\"바꿀 문자열을 입력하세요 : \";
cin>>change_text;
text.replace(text.find(search_text),change_text.length(),change_text);
cout<
}
소개글