hugDog
Android DevLog
hugDog
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
  • ๐Ÿ™Œ Hello? (162)
    • ๐Ÿงฉ์•ˆ๋“œ๋กœ์ด๋“œ (12)
      • ๊ฐœ๋… ์ •๋ฆฌ (5)
      • ๋ฒ„๊ทธ ํ•ด๊ฒฐ (4)
      • ๊ธฐํƒ€ (3)
    • ๐Ÿ”์•Œ๊ณ ๋ฆฌ์ฆ˜ (54)
      • ๊ฐœ๋… (0)
      • ๋ฐฑ์ค€ (48)
      • ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค (6)
    • ๐Ÿ“„๊ฐœ๋ฐœ ์ผ์ง€ (0)
      • FINPO (0)
    • ๐Ÿ”คํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด (71)
      • C++ ์ •๋ฆฌ (49)
      • C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค ์—ฐ์Šต๋ฌธ์ œ (20)
      • Kotlin (2)
    • โญProject (1)
    • ๐ŸšดTIL (13)
      • Clean Code (13)
    • ๐Ÿšฉ๊ธฐํƒ€ (9)
      • ๋ชฉํ‘œ (6)
      • ์ผ์ƒ (3)
      • ๋ฌธ์„œ (0)

์ธ๊ธฐ ๊ธ€

์ตœ๊ทผ ๋Œ“๊ธ€

์ตœ๊ทผ ๊ธ€

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
hugDog
๐Ÿ”คํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด/C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค ์—ฐ์Šต๋ฌธ์ œ

(C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค 6ํŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ฐ์Šต ์ •๋‹ต,์†”๋ฃจ์…˜) CHAPTER 09 ๋ฉ”๋ชจ๋ฆฌ ๋ชจ๋ธ๊ณผ ์ด๋ฆ„ ๊ณต๊ฐ„ p.630~ 1๋ฒˆ~4๋ฒˆ

๐Ÿ”คํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด/C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค ์—ฐ์Šต๋ฌธ์ œ

(C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค 6ํŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ฐ์Šต ์ •๋‹ต,์†”๋ฃจ์…˜) CHAPTER 09 ๋ฉ”๋ชจ๋ฆฌ ๋ชจ๋ธ๊ณผ ์ด๋ฆ„ ๊ณต๊ฐ„ p.630~ 1๋ฒˆ~4๋ฒˆ

2020. 9. 4. 15:06
728x90

1๋ฒˆ

//golf.cpp
#include"golf.h"
#include<string>
#include<iostream>

void setgolf(golf& g, const char* name, int hc)
{
	strcpy(g.fullname, name);
	g.handicap = hc;
}

int setgolf(golf& g)
{
	using std::cout;
	cout << "์ด๋ฆ„ ์ž…๋ ฅ : ";
	std::cin.getline(g.fullname, 40);
	if (g.fullname[0] == '\0')
	{
		cout << "์ด๋ฆ„์ด ์ž…๋ ฅ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.\n";
		return 0;
	}
	cout << "ํ•ธ๋””์บก ์ž…๋ ฅ : ";
	(std::cin >> g.handicap).get();
	return 1;
}

void handicap(golf& g, int hc)
{
	g.handicap = hc;
}

void showgolf(const golf& g)
{
	using std::cout;
	using std::endl;
	cout << "์ด๋ฆ„ : " << g.fullname << endl
		<< "ํ•ธ๋””์บก : " << g.handicap << endl;
	
}




//golf.h
const int Len = 40;
struct golf
{
	char fullname[Len];
	int handicap;
};

void setgolf(golf& g, const char* name, int hc);
int setgolf(golf& g);
void handicap(golf& g, int hc);
void showgolf(const golf& g);





//main.cpp
#include<iostream>
#include"golf.h"

int main()
{
	using std::cout;
	golf ann;
	golf andy;
	setgolf(ann, "Ann Birdfree", 24);
	showgolf(ann);
	cout << "ann์˜ ํ•ธ๋””์บก ์ˆ˜์ •\n";
	handicap(ann, 30);
	showgolf(ann);
	cout << "andy์˜ ์ •๋ณด ์ž…๋ ฅ\n";
	if(setgolf(andy))
		showgolf(andy);

	cout << "\n\ngolf ๊ตฌ์กฐ์ฒด์˜ ๋ฐฐ์—ด์— ์ž…๋ ฅ์„ ์š”๊ตฌ\n\n";

	golf ar[5];
	int i;
	for (i = 0; i < 5; i++)
	{
		if (setgolf(ar[i]) == 0)
			break;
	}

	cout << "\n\ngolf ๊ตฌ์กฐ์ฒด์˜ ๋ฐฐ์—ด์ถœ๋ ฅ\n\n";
	for (int j = 0; j < i; j++)
		showgolf(ar[j]);
}

 

2๋ฒˆ

// static.cpp -- ์ •์  ์ง€์—ญ ๋ณ€์ˆ˜ ์‚ฌ์šฉํ•˜๊ธฐ
#include <iostream>
#include<string>
// ์ƒ์ˆ˜
using namespace std;

// ํ•จ์ˆ˜ ์›ํ˜•
void strcount(string str);

int main()
{
	using namespace std;
	string input;
	char next;

	cout << "์˜๋ฌธ์œผ๋กœ ํ•œ ํ–‰์„ ์ž…๋ ฅํ•˜์‹ญ์‹œ์˜ค:\n";
	getline(cin, input);
	while (input!="")
	{
		strcount(input);
		cout << "๋‹ค์Œ ํ–‰์„ ์ž…๋ ฅํ•˜์‹ญ์‹œ์˜ค(๋๋‚ด๋ ค๋ฉด ๋นˆ ํ–‰์„ ์ž…๋ ฅ):\n";
		getline(cin, input);
	}
	cout << "ํ”„๋กœ๊ทธ๋žจ์„ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.\n";
	return 0;
}

void strcount(string str)
{
	using namespace std;
	static int total = 0;			// ์ •์  ์ง€์—ญ ๋ณ€์ˆ˜
	int count = 0;				// ์ž๋™ ์ง€์—ญ ๋ณ€์ˆ˜

	cout << "\"" << str << "\"์—๋Š” ";
	while (str[count++])				// ๋ฌธ์ž์—ด์˜ ๋๊นŒ์ง€ ์นด์šดํŠธํ•œ๋‹ค
		;
	count -= 1;
	total += count;
	cout << count << "๊ฐœ์˜ ๋ฌธ์ž๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.\n";
	cout << "์ง€๊ธˆ๊นŒ์ง€ ์ด " << total << "๊ฐœ์˜ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•˜์…จ์Šต๋‹ˆ๋‹ค.\n";
}

 

 

3๋ฒˆ

#include<iostream>
#include<string>
#include<new>
struct chaff
{
	char dross[20];
	int slag;
};
char buffer1[500];

void show(struct chaff& a);

int main()
{
	using std::cout;
	using std::endl;
	chaff *a = new (buffer1) chaff[2];
	cout << "๋ฒ„ํผ์— ์ •์  ๋ฐฐ์—ด ์‚ฌ์šฉ" << endl;
	if (a == NULL) return -1;
	strcpy(a[0].dross, "abcdef");
	a[0].slag = 3;
	strcpy(a[1].dross, "qwerty");
	a[1].slag = 20;
	for (int i = 0; i < 2; i++)
		show(a[i]);

	cout << "\n๋ณดํ†ต์˜ new๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฒ„ํผ ๋Œ€์ž…" << endl;
	char* buffer2 = new char[500];
	chaff* a2 = new (buffer2) chaff[2];
	if (a2 == NULL) return -1;
	strcpy(a2[0].dross, "twoaaa");
	a2[0].slag = 9;
	strcpy(a2[1].dross, "lkjhg");
	a2[1].slag = -3;
	for (int i = 0; i < 2; i++)
		show(a2[i]);
	delete[]buffer2;

	return 0;
}

void show(struct chaff& a)
{
	using std::cout;
	using std::endl;
	cout << a.dross << endl
		<< a.slag << endl;
}

 

 

4๋ฒˆ

//sale.h
namespace SALES
{
	const int QUARTERS = 4;
	struct Sales
	{
		double sales[QUARTERS];
		double average;
		double max;
		double min;
	};

	void setSales(Sales& s, const double ar[], int n);
	void setSales(Sales& s);
	void showSales(const Sales& s);
}

//sale.cpp
#include<iostream>
#include"sale.h"
using namespace std;

namespace SALES
{
	void setSales(Sales& s, const double ar[], int n)
	{
		if (n < 4)
		{
			for (int i = n; i < 4; i++)
				s.sales[i] = 0;
		}
		else n = 4;
		for (int i = 0; i < n; i++)
			s.sales[i] = ar[i];
		s.max = s.min = s.average = s.sales[0];
		for (int i = 1; i < n; i++)
		{
			if (s.sales[i] > s.max) s.max = s.sales[i];
			if (s.sales[i] < s.min) s.min = s.sales[i];
			s.average += s.sales[i];
		}
		s.average /= n;
	}

	void setSales(Sales& s)
	{
		for (int i = 0; i < 4; i++)
		{
			cout << i + 1 << "๋ถ„๊ธฐ๋ณ„ ํŒ๋งค์•ก : ";
			cin >> s.sales[i];
		}
		s.max = s.min = s.average = s.sales[0];
		for (int i = 1; i < 4; i++)
		{
			if (s.sales[i] > s.max) s.max = s.sales[i];
			if (s.sales[i] < s.min) s.min = s.sales[i];
			s.average += s.sales[i];
		}
		s.average /= 4;
	}

	void showSales(const Sales& s)
	{
		for (int i = 0; i < 4; i++)
			cout << i + 1 << "๋ถ„๊ธฐ ํŒ๋งค์•ก : " << s.sales[i] << endl;
		cout << "์ตœ๋Œ€๊ฐ’ : " << s.max << endl
			<< "์ตœ์†Œ๊ฐ’ : " << s.min << endl
			<< "ํ‰๊ท ๊ฐ’ : " << s.average << endl;
	}
}

//main.cpp
#include<iostream>
#include"sale.h"

int main()
{
	using namespace std;
	using namespace SALES;
	Sales a1, a2, a3;
	double test1[2] = { 3.1,9.7 };
	double test2[4] = { 1.4,2.5,3.2,6.5 };
	setSales(a1, test1, 2);
	setSales(a2, test2, 4);
	showSales(a1); showSales(a2);

	cout << endl << endl;
	setSales(a3);
	showSales(a3);

}
728x90
์ €์ž‘์žํ‘œ์‹œ ๋น„์˜๋ฆฌ (์ƒˆ์ฐฝ์—ด๋ฆผ)
    '๐Ÿ”คํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด/C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค ์—ฐ์Šต๋ฌธ์ œ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • (C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค 6ํŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ฐ์Šต ์ •๋‹ต,์†”๋ฃจ์…˜) CHAPTER 11 ํด๋ž˜์Šค์˜ ํ™œ์šฉ p.787~ 1๋ฒˆ~7๋ฒˆ
    • (C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค 6ํŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ฐ์Šต ์ •๋‹ต,์†”๋ฃจ์…˜) CHAPTER 10 ๊ฐ์ฒด์™€ ํด๋ž˜์Šค p.705~ 1๋ฒˆ~8๋ฒˆ
    • (C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค 6ํŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ฐ์Šต ์ •๋‹ต,์†”๋ฃจ์…˜) CHAPTER 08 ํ•จ์ˆ˜์˜ ํ™œ์šฉ p.555~ 1๋ฒˆ~7๋ฒˆ
    • (C++๊ธฐ์ดˆํ”Œ๋Ÿฌ์Šค 6ํŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ฐ์Šต ์ •๋‹ต,์†”๋ฃจ์…˜) CHAPTER 07 ํ•จ์ˆ˜-C++์˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ชจ๋“ˆ p.462~ 7๋ฒˆ~10๋ฒˆ
    hugDog
    hugDog
    ์•ˆ๋“œ๋กœ์ด๋“œ ๊ณต๋ถ€ ์ค‘์ธ ํ•™์ƒ์ž…๋‹ˆ๋‹ค!

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”

    ๊ฐœ์ธ์ •๋ณด

    • ํ‹ฐ์Šคํ† ๋ฆฌ ํ™ˆ
    • ํฌ๋Ÿผ
    • ๋กœ๊ทธ์ธ

    ๋‹จ์ถ•ํ‚ค

    ๋‚ด ๋ธ”๋กœ๊ทธ

    ๋‚ด ๋ธ”๋กœ๊ทธ - ๊ด€๋ฆฌ์ž ํ™ˆ ์ „ํ™˜
    Q
    Q
    ์ƒˆ ๊ธ€ ์“ฐ๊ธฐ
    W
    W

    ๋ธ”๋กœ๊ทธ ๊ฒŒ์‹œ๊ธ€

    ๊ธ€ ์ˆ˜์ • (๊ถŒํ•œ ์žˆ๋Š” ๊ฒฝ์šฐ)
    E
    E
    ๋Œ“๊ธ€ ์˜์—ญ์œผ๋กœ ์ด๋™
    C
    C

    ๋ชจ๋“  ์˜์—ญ

    ์ด ํŽ˜์ด์ง€์˜ URL ๋ณต์‚ฌ
    S
    S
    ๋งจ ์œ„๋กœ ์ด๋™
    T
    T
    ํ‹ฐ์Šคํ† ๋ฆฌ ํ™ˆ ์ด๋™
    H
    H
    ๋‹จ์ถ•ํ‚ค ์•ˆ๋‚ด
    Shift + /
    โ‡ง + /

    * ๋‹จ์ถ•ํ‚ค๋Š” ํ•œ๊ธ€/์˜๋ฌธ ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ํ‹ฐ์Šคํ† ๋ฆฌ ๊ธฐ๋ณธ ๋„๋ฉ”์ธ์—์„œ๋งŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.