Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 리눅스
- Virtual Box
- 네트워크
- 기초
- shell
- MariaDB
- Web shell
- nomaltic
- Error
- 리눅스 기초
- Vitual Disk Image
- virtualbox
- nomaltic place
- 노말틱
- Bitnami
- VDI
- kali
- 보안
- Linux
- 칼리 리눅스
- kali linux
- Normaltic
- mysql
- Bandit
- 칼리
Archives
- Today
- Total
게으른 개발자
[3]명품 C++ Programming -2장[c++프로그래밍 기본](2)-[실습 문제] 본문
C++/명품 C++ Programming
[3]명품 C++ Programming -2장[c++프로그래밍 기본](2)-[실습 문제]
Tomato_Coffee 2022. 5. 6. 16:051번
#include<iostream>
using namespace std;
int main() {
for (int i = 1; i <= 100; i++) {
cout << i << '\t';
if (i % 10 == 0)
cout << endl;
}
}
2번
#include<iostream>
using namespace std;
int main() {
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++)
cout << j << "x" << i << "=" << j * i<<"\t";
cout << endl;
}
}
3번
#include<iostream>
using namespace std;
int main() {
cout << "두 수를 입력하라>>";
int a, b;
cin >> a >> b;
cout << "큰 수 = ";
a > b ? cout << a : cout << b;
}
4번
#include<iostream>
using namespace std;
int main() {
double arr[5];
cout << "5 개의 실수를 입력하라>>";
double max;
cin >> arr[0];
max = arr[0];
for (int i = 1; i < 5; i++)
cin >> arr[i];
cout << "제일 큰 수 = "<<max;
}
5번
#include<iostream>
using namespace std;
int main() {
char arr[100];
int count = 0;
cout << "문자들을 입력하라(100개미만)." << endl;
cin.getline(arr, 100, '\n');
//cout << arr;
//cout << arr[0];
for (int i = 0;arr[i]; i++)
{
//cout << "1" << endl;
if (arr[i] == 'x')
count++;
}
cout <<"x의 개수는 " <<count;
}
6번
#include<iostream>
#include<string>
using namespace std;
int main() {
string a, b;
cout << "새 암호를 입력하세요>>";
cin >> a;
cout << "새 암호를 다시 한 번 입력하세요>>";
cin >> b;
if (a == b)
cout << "같습니다." << endl;
else
cout << "같지 않습니다." << endl;
}
7번
#include<iostream>
#include<string>
using namespace std;
int main() {
string a, b;
while (true) {
cout << "종료하고싶으면 yes를 입력하세요>>";
getline(cin, a, '\n');
if (a == "yes")
{ cout << "종료합니다..." << endl;
break;}
}
}
8번
#include<iostream>
#include<string>
using namespace std;
int main()
{
string a;
string b;
int max = 0;
cout << "5 명의 이름을 ';'으로 구분하여 입력하세요" << endl;
for (int i = 1; i <= 5; i++)
{
getline(cin, a, ';');
cout << i << " : " << a << endl;
if (max < a.length())
{
max = a.length();
b = a;
}
}
cout << "가장 긴 이름은 " << b << endl;
}
9번
#include<iostream>
#include<string>
using namespace std;
int main() {
string a;
string b;
int c;
cout << "이름은?";
getline(cin, a, '\n');// "\n" 넣으면 빨간줄뜸
cout << "주소는?";
getline(cin, b, '\n');
cout << "나이는?";
cin >> c;
cout << a << ", " << b << ", " << c << "세" << endl;
}
10번
#include<iostream>
#include<string>
using namespace std;
int main() {
string a;
cout << "문자열 입력>>";
cin >> a;
for (int i = 0; i < a.length(); i++)
{
for (int j = 0; j <= i; j++) {
cout << a[j];
}
cout << endl;
}
}
11번
#include<iostream>
#include<string>
using namespace std;
int main() {
int k, n=0;
int sum = 0;
cout << "끝 수를 입력하세요>>";
cin >> n;
for (k = 1; k <= n; k++)
sum += k;
cout << "1에서 " << n << "까지의 합은 " << sum << "입니다." << endl;
}
12번
#include<iostream>
using namespace std;
int sum(int, int);
int main() {
int n = 0;
cout << "끝 수를 입력하세요>>";
cin >> n;
cout << "1에서 " << n << "까지의 합은 " << sum(1, n) << "입니다." << endl;
}
int sum(int x, int y) {
int k, res = 0;
for (k = x; k <= y; k++)
res += k;
return res;
}
13번
#include<iostream>
using namespace std;
int main() {
cout << "***** 승리장에 오신 것을 환영합니다. *****" << endl;
int n;
int s = 0;
while (true) {
cout << "짬뽕:1, 짜장:2, 군만두:3, 종료:4>> ";
cin >> n;
s = 0;
if (n > 4)
{
cout << "다시 주문하세요!!" << endl;
continue;
}
if (n == 4)
{
cout << "오늘 영업은 끝났습니다." << endl;
break;
}
if (n == 1)
{
cout << "몇인분?";
cin >> s;
cout << "짬뽕 " << s << "인분 나왔습니다." << endl;
}
if (n == 2)
{
cout << "몇인분?";
cin >> s;
cout << "짜장 " << s << "인분 나왔습니다." << endl;
}
if (n == 3)
{
cout << "몇인분?";
cin >> s;
cout << "군만두 " << s << "인분 나왔습니다." << endl;
}
}
}
14번
#include<iostream>
#include<cstring>
using namespace std;
int main() {
char coffee[100];
int num;
int sum = 0;
int flag = 0;
cout << "에스프레소 2000원, 아메리카노 2300원, 카푸치노 2500원입니다." << endl;
while (true) {
if (flag == 1)
{
cout << "오늘 " << sum << "원을 판매하여 카페를 닫습니다. 내일 봐요~~~" << endl;
break;
}
cin >> coffee >> num;
if (strcmp(coffee, "에스프레소") == 0)
{
cout << 2000 * num << "원입니다. 맛있게 드세요" << endl;
sum += 2000 * num;
if (sum >= 20000)
flag = 1;
}
else if (strcmp(coffee, "아메리카노") == 0)
{
cout << 2300 * num << "원입니다. 맛있게 드세요" << endl;
sum += 2300 * num;
if (sum >= 20000)
flag = 1;
}
else
{
cout << 2500 * num << "원입니다. 맛있게 드세요" << endl;
sum += 2500 * num;
if (sum >= 20000)
flag = 1;
}
}
}
15번
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main() {
char arr[100];
int a, b;
char* oper;
char* context=nullptr;
while (true) {
cout << "? ";
cin.getline(arr,100, '\n');//#include<string> 해야 사용가능
a = atoi(strtok_s(arr, " ", &context));
oper = strtok_s(NULL, " ", &context);// NULL을 매개변수를 써줘야 이전에 나눴던 문자열로 돌라가서 임무를 수행함
b = atoi(strtok_s(NULL, " ", &context));//즉, 이전에 찾은 구분자 뒤에서 부터 다시 구분자를 찾게 됨.
if (*oper == '+') {// 참조값이랑 비교를 해야함 *oper == ' + ' 이렇게
cout << a << " + " << b << " = " << a + b << endl;
}
else if (*oper == '-') {
cout << a << " - " << b << " = " << a - b << endl;
}
else if (*oper == '*') {
cout << a << " * " << b << " = " << a * b << endl;
}
else if (*oper == '/') {
cout << a << " / " << b << " = " << a / b << endl;
}
else {// 이때는 % 연산자일때
cout << a << " % " << b << " = " << a % b << endl;
}
}
}
16번
#include<iostream>
#include<cctype>
using namespace std;
int main() {
cout << "영문 텍스트를 입력하세요. 히스토그램을 그립니다." << endl;
cout << "텍스트의 끝은 ; 입니다. 10000개까지 가능합니다." << endl;
char buf[10000];
int sum = 0;
int cnt = 0;
cin.getline(buf, 10000, ';');
for (int i = 0; buf[i]; i++) {
if (isalpha(buf[i]) != 0) {
sum++;
}
}
cout << "총 알파벳 수 " << sum << endl<< endl<<endl;
for (char k = 'a'; k <= 'z'; k++) {
cnt = 0;
for (int i = 0; buf[i]; i++) {
if (isalpha(buf[i]) != 0) {
if (tolower(buf[i]) == k)
cnt++;
}
}
cout << k << " (" << cnt << ")\t" << ": ";
for (int j = 0; j < cnt; j++)
cout << "*";
cout << endl;
}
}
'C++ > 명품 C++ Programming' 카테고리의 다른 글
[6]명품 C++ Programming -4장[객체 포인터와 객체 배열, 객체의 동적 생성](1)-[내용 정리] (0) | 2022.05.23 |
---|---|
[5]명품 C++ Programming -3장[클래스와 객체](2)-[실습 문제] (0) | 2022.05.21 |
[4]명품 C++ Programming -3장[클래스와 객체](1)-[내용 정리] (0) | 2022.05.06 |
[2]명품 C++ Programming -2장[c++프로그래밍 기본](1)-[2장 내용 정리] (0) | 2022.05.06 |
[1]명품 C++ Programming -1장 c++시작[Visual studio 설정& 실습] (0) | 2022.04.29 |