개발관련
[11강-20강][하루 10분|C++] 누구나 쉽게 배우는 C++ 프로그래밍 입문 요약
유미포
2021. 7. 7. 00:44
앞의 강의 내용을 보기 위해서는 이 포스트를 참고해주세요
2021.07.03 - [1강-10강][하루 10분|C++] 누구나 쉽게 배우는 C++ 프로그래밍 입문 요약
[1강-10강][하루 10분|C++] 누구나 쉽게 배우는 C++ 프로그래밍 입문 요약
[하루 10분|C++] 누구나 쉽게 배우는 C++ 프로그래밍 입문 요약 본 포스트는 구름에서 제공하는 무료 강의를 기반으로 작성되었습니다. 아직 강의 관련 요약이 인터넷에 없는것같아 포스트로 남겨
yumissfortune.tistory.com
11강 : 구조체
구조체 뒤에 이름을 선언하면 구조페명을 쓰지 않고도 바로 선언할 수 있다. (이 경우 B)
#include <iostream>
#include <cstring>
using namespace std;
int main(){
struct MyStruct
{
string name;
string position;
int height;
int weight;
} B;
MyStruct A;
A.name = "Son";
A.position = "Striker";
A.height = 183;
A.weight = 77;
/*
MyStruct A = {
"Son",
"Striker",
183,
77
}
*/
cout << A.name << endl;
cout << A.position << endl;
cout << A.height << endl;
cout << A.weight << endl;
B = {
};
cout << B.height << endl;
MyStruct C[2] = {
{"A", "A", 1, 1},
{"B", "B", 2, 2}
};
cout << C[0].height << endl;
return 0;
}
12강 공용체와 열거체
#include <iostream>
#include <cstring>
using namespace std;
int main(){
//공용체
//서로 다른 데이터형을 한번에 한가지만 보관할 수 있음
//새로운 데이처형 입력시 이전꺼는 이상해짐
union MyUnion{
int intVal;
long longVal;
float floatVal;
};
MyUnion test;
test.intVal = 3;
test.longVal = 33;
test.floatVal = 3.3;
std::cout<< test.longVal << std::endl;
return 0;
}
#include <iostream>
#include <cstring>
using namespace std;
int main(){
//열거체
//기호 상수를 만드는 것에 대한 또다른 방법
enum spectrum{ red, orange, yellow, green, blue, violet };
/*
* spectrum을 새로운 데이터형 이름으로 만든다
* red, orange, yellow 0에서부터 7까지 정수값을 각각 나타내는 기호 상수로 만든다.
*/
spectrum a = yellow;
std::cout << a<< std::endl;
int b = blue+3;
std::cout << b << std::endl;
return 0;
}
13강 포인터와 메모리 해제
#include <iostream>
using namespace std;
int main(){
int a = 6;
int* b;
b = &a;
cout << "a의 값 " << a << endl;
cout << "*b의 값 " << *b << endl;
cout << "a의 주소 " << &a << endl;
cout << "*b의 주소 " << b << endl;
*b = *b + 1;
cout << "이제 a의 값은 " << a << endl;
return 0;
}
14강 포인터와 메모리 해제 2
#include <iostream>
using namespace std;
int main(){
double* p3 = new double[3];
p3[0] = 0.2;
p3[1] = 0.5;
p3[2] = 0.8;
cout << "p3[1] is " << p3[1] << ".\n";
p3 = p3 + 1;
cout << "Now p3[0] is " << p3[0] << " and ";
cout << "p3[1] is " << p3[1] << "\n.";
p3 = p3-1;
delete[] p3;
return 0;
}
15강 포인터와 배열/ 문자열
이 부분은 C와 많이 비슷한것같습니다.
#include <iostream>
#define SIZE 20
using namespace std;
int main(){
char animal[SIZE];
char* ps;
cout << "동물 이름을 입력하십시오.\n";
cin >> animal;
ps = new char[strlen(animal) +1];
strcpy(ps, animal);
cout << "입력하신 동물 이름을 복사하였습니다." << endl;
cout << "입력하신 동물 이름은 " << animal << "이고, 그 주소는 " << (int*)animal << " 입니다." << endl;
cout << "복사된 동물 이름은 " << ps << "이고, 그 주소는 " << (int*)ps << " 입니다." << endl;
return 0;
}
#include <iostream>
#define SIZE 20
using namespace std;
struct MyStruct
{
char name[20];
int age;
};
int main(){
MyStruct* temp = new MyStruct;
cout << "당신의 이름을 입력하십시오.\n";
cin >> temp->name;
cout << "당신의 나이를 입력하십시오.\n";
cin >> (*temp).age;
cout << "안녕하세요! " << temp->name << "씨!\n";
cout << "당신은 " << temp->age << "살 이군요!\n";
return 0;
}
16강 반복문
자바와 다를것이 없습니다.
#include <iostream>
using namespace std;
int main(){
char a[10] = {'a', 'b', 'c', 'd', 'e'};
for (int i=0; i<5; i++){
cout<<a[i]<<endl;
}
}
17강 증가/ 감소연산자
++a : 먼저 1더한값을 a에 저장하고 수행
a++ : a에 먼저 수행하고 나중에 1더하기
<
>
<=
>=
==
!=
는 다른언어와 같습니다.
18강 while loop and do while loop
#include <iostream>
using namespace std;
int main(){
char a[10] = {'a', 'b', 'c', 'd', 'e'};
int i=0;
while(i < 3){
i++;
cout<<i<<endl;
}
}
#include <iostream>
using namespace std;
int main(){
char a[10] = {'a', 'b', 'c', 'd', 'e'};
int i=3;
do{
i++;
cout<<i<<endl;
}while(i < 3);
}
19강 if
#include <iostream>
using namespace std;
int main(){
int i = 10;
if (i > 10){
cout<< "Hello" <<endl;
}
else if (i == 10){
cout<< "Good Evening" <<endl;
}
else{
cout<< "Good Night" <<endl;
}
}
20강 논리연산자
다른 언어와 모두 같습니다 ( 자바 등 )