<head>
<title>My Blog Page</title>
<style>
body {
background-color : #efe5d0;
font-family: Arial, "Trebuchet MS", sans-serif;
margin : 0px;
}
header{
background-color:#e3afed;
color:#000000;
margin:0px;
text-align : center;
padding:5px;
}
h1{
margn : 0px;
}
section#main{
display : table-cell;
background-color:yellow;
padding:15px;
}
nav{
display:table-cell;
background-color:#ffd800;
padding:15px;
}
footer{
background-color:#954b4b;
color:#efe5d0;
text-align : center;
padding: 10px;
margin: 0px 0px 0px 0px;
font-size:90%;
}
</style>
</head>
<body>
<header>
<h1>My Blog Page</h1>
</header>
<nav>
<h1>Links</h1>
<ul>
<li><a href = "http://www.w3c.org/">W3C</a></li>
<li><a href = "#">MOZILLA</a></li>
<li><a href = "#">HTML DOGS</a></li>
</ul>
<figure>
<img width = "85" heigh ="85"
src = "hong.png"
alt = "홍길동" />
<figcaption>홍길동</figcaption>
</figure>
</nav>
<section id = "main">
<article>
<h1>Semantic Tags</h1>
<p>시맨택 요소는 브라우저에게 요소의 의미와 목적을 명확하게 알려주는 요소임</p>
</article>
<article>
<h1>div and span</h1>
<p>div 는 "divide"의 약자로서 페이지를 논리적인 섹션으로 분리하는 데 사용되는 태그이다.
span 요소는 인라인 요소로서 텍스트를 위한 컨테이너로 사용할 수 있다.</p>
</article>
</sextion>
<footer>Copyright (c) 2013 Hong </footer>
12.19.2017
12.06.2017
#include <iostream>
#include <string>
#include <list>
using namespace std;
struct record{
string name;
int score;
};
void read_data(list<record> &a){ //call by reference, &안하면 그 안에 복사가 되지 않음.
record x;
for(int i = 0; i < 10; i++){
cout << "Enter name and score: ";
cin >> x.name >> x.score; //안하면 쓰레기값 10번 넣어주는 거임
a.push_back(x);
}
/* 10이 아니라 size로 돌릴 때
while(true){
cout << "Enter name and score: ";
cin >> x.name;
if(x.name == "quit") break;
cin >> x.score;
a.push_back(x);
}*/
}
void find(list<record> &a){
string name;
cout << "Enter name to find: ";
cin >> name;
for(int i = 0; i < a.size(); i++){
if(a[i].name == name){
cout << a[i].score << endl;
return;
}
} cout << "찾을 수 없습니다." << endl;
/*iterator로 하기
list<record>::iterator it;
for(it = a.begin(); it != a.end(){
if(it->name == name){
cout << a[i].score << endl;
return;
}
} cout << "찾을 수 없습니다. " <<endl;
*/
}
int main(){
list<record> a;
read_data(a);
find(a);
system("pause");
return 0;
}
#include <string>
#include <list>
using namespace std;
struct record{
string name;
int score;
};
void read_data(list<record> &a){ //call by reference, &안하면 그 안에 복사가 되지 않음.
record x;
for(int i = 0; i < 10; i++){
cout << "Enter name and score: ";
cin >> x.name >> x.score; //안하면 쓰레기값 10번 넣어주는 거임
a.push_back(x);
}
/* 10이 아니라 size로 돌릴 때
while(true){
cout << "Enter name and score: ";
cin >> x.name;
if(x.name == "quit") break;
cin >> x.score;
a.push_back(x);
}*/
}
void find(list<record> &a){
string name;
cout << "Enter name to find: ";
cin >> name;
for(int i = 0; i < a.size(); i++){
if(a[i].name == name){
cout << a[i].score << endl;
return;
}
} cout << "찾을 수 없습니다." << endl;
/*iterator로 하기
list<record>::iterator it;
for(it = a.begin(); it != a.end(){
if(it->name == name){
cout << a[i].score << endl;
return;
}
} cout << "찾을 수 없습니다. " <<endl;
*/
}
int main(){
list<record> a;
read_data(a);
find(a);
system("pause");
return 0;
}
1206 vector
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct record{
string name;
int score;
};
void read_data(vector<record> &a){ //call by reference, &안하면 그 안에 복사가 되지 않음.
record x;
for(int i = 0; i < 10; i++){
cout << "Enter name and score: ";
cin >> x.name >> x.score; //안하면 쓰레기값 10번 넣어주는 거임
a.push_back(x);
}
/* 10이 아니라 size로 돌릴 때
while(true){
cout << "Enter name and score: ";
cin >> x.name;
if(x.name == "quit") break;
cin >> x.score;
a.push_back(x);
}*/
}
void find(vector<record> &a){
string name;
cout << "Enter name to find: ";
cin >> name;
for(int i = 0; i < a.size(); i++){
if(a[i].name == name){
cout << a[i].score << endl;
return;
}
} cout << "찾을 수 없습니다." << endl;
/*int i;
for(i = 0; i < a.size(); i++) {
if(name != a[i].name){
cout << i << a[i].score << endl;
break;
}
}
if(i == a.size()) cout << "찾을 수 없습니다." << endl;
*/
/*iterator로 하기
vector<record>::iterator it;
for(it = a.begin(); it != a.end(){
if(it->name == name){
cout << a[i].score << endl;
return;
}
} cout << "찾을 수 없습니다. " <<endl;
*/
}
int main(){
vector<record> a;
read_data(a);
find(a);
system("pause");
return 0;
}
#include <string>
#include <vector>
using namespace std;
struct record{
string name;
int score;
};
void read_data(vector<record> &a){ //call by reference, &안하면 그 안에 복사가 되지 않음.
record x;
for(int i = 0; i < 10; i++){
cout << "Enter name and score: ";
cin >> x.name >> x.score; //안하면 쓰레기값 10번 넣어주는 거임
a.push_back(x);
}
/* 10이 아니라 size로 돌릴 때
while(true){
cout << "Enter name and score: ";
cin >> x.name;
if(x.name == "quit") break;
cin >> x.score;
a.push_back(x);
}*/
}
void find(vector<record> &a){
string name;
cout << "Enter name to find: ";
cin >> name;
for(int i = 0; i < a.size(); i++){
if(a[i].name == name){
cout << a[i].score << endl;
return;
}
} cout << "찾을 수 없습니다." << endl;
/*int i;
for(i = 0; i < a.size(); i++) {
if(name != a[i].name){
cout << i << a[i].score << endl;
break;
}
}
if(i == a.size()) cout << "찾을 수 없습니다." << endl;
*/
/*iterator로 하기
vector<record>::iterator it;
for(it = a.begin(); it != a.end(){
if(it->name == name){
cout << a[i].score << endl;
return;
}
} cout << "찾을 수 없습니다. " <<endl;
*/
}
int main(){
vector<record> a;
read_data(a);
find(a);
system("pause");
return 0;
}
11.15.2017
<mystring.h> header file
#include <iostream>
using namespace std;
class mystring {
private:
int len;
char *str;
public:
mystring() : str(NULL), len(0) { }
mystring(char *s) : str(new char[len+1]), len(length(s)) { copy(s); }
mystring(const mystring &s)
: str(new char[len+1]),
len(length(s.str))
{
copy(s.str);
}
~mystring()
{
if (str != NULL) {
delete []str;
str = NULL;
len = 0;
}
}
char *get_string()
{
return str;
}
void set_string(char *s)
{
len = length(s);
if (str != NULL) delete []str;
str = new char[len+1];
copy(s);
}
private:
int length(char *s)
{
int len = 0;
while (*s++ != '\0') len++;
return len;
}
void copy(char *s)
{
for (int i = 0; i <= len; i++) str[i] = s[i];
}
};
#include <iostream>
using namespace std;
class mystring {
private:
int len;
char *str;
public:
mystring() : str(NULL), len(0) { }
mystring(char *s) : str(new char[len+1]), len(length(s)) { copy(s); }
mystring(const mystring &s)
: str(new char[len+1]),
len(length(s.str))
{
copy(s.str);
}
~mystring()
{
if (str != NULL) {
delete []str;
str = NULL;
len = 0;
}
}
char *get_string()
{
return str;
}
void set_string(char *s)
{
len = length(s);
if (str != NULL) delete []str;
str = new char[len+1];
copy(s);
}
private:
int length(char *s)
{
int len = 0;
while (*s++ != '\0') len++;
return len;
}
void copy(char *s)
{
for (int i = 0; i <= len; i++) str[i] = s[i];
}
};
<main.cpp>
#include "mystring.h"
void print_safe(mystring &s)
{
cout << "safe: " << s.get_string() << endl;
}
void print_dangerous(mystring &s)
{
cout << "dangerous: " << s.get_string() << endl;
}
void print()
{
mystring a("C++ Programming");
print_safe(a);
print_dangerous(a);
}
void foo()
{
mystring a("Sungshin University");
mystring b = a;
print_safe(a);
print_safe(b);
}
int main()
{
print();
foo();
system("pause");
return 0;
}
10.31.2017
#include <iostream>
using namespace std;
struct myvector{
int *p;
int size;
int next;
}
int get_size(myvector &m){
//data개수 return
return m.next;
}
int get_maxsize(myvector &m){
//크기 return
return m.size;
}
int get_value(myvector &m, int i){
//a의 p의 i번방
return m.p[i];
}
int set_value(myvector &m, int i, int v){
//a의 i번 방을 v로 바꿔라
return m.p[i] = v;
}
void push_back(myvector &m, int v){
//제일 뒤에 5를 넣어라(next가 가리키고 있는 방에 넣기)
m.p[m.next++] = v;
}
void clear(myvector &m){
//다 지우고 다시 시작(next가 0)
m.next = 0;
}
int main(){
myvector a;
get_size(a);
get_maxsize(a);
get_value(a, i);
set_value(a, b, c);
push_back(a, d);
clear(a);
}
using namespace std;
struct myvector{
int *p;
int size;
int next;
}
int get_size(myvector &m){
//data개수 return
return m.next;
}
int get_maxsize(myvector &m){
//크기 return
return m.size;
}
int get_value(myvector &m, int i){
//a의 p의 i번방
return m.p[i];
}
int set_value(myvector &m, int i, int v){
//a의 i번 방을 v로 바꿔라
return m.p[i] = v;
}
void push_back(myvector &m, int v){
//제일 뒤에 5를 넣어라(next가 가리키고 있는 방에 넣기)
m.p[m.next++] = v;
}
void clear(myvector &m){
//다 지우고 다시 시작(next가 0)
m.next = 0;
}
int main(){
myvector a;
get_size(a);
get_maxsize(a);
get_value(a, i);
set_value(a, b, c);
push_back(a, d);
clear(a);
}
3주차 과제
#include <iostream>
#include <fstream>
using namespace std;
struct course {
char subject[64];
int studentNum;
int score[256];
};
void process(ifstream &fin, course &a)
{
int sum = 0;
double ave = 0;
fin >> a.subject;
if (!fin.eof()) {
cout << a.subject;
fin >> a.studentNum;
a.score = new int[a.studentNum];
for (int j = 0; j < a.studentNum; j++) {
fin >> a.score[j];
sum += a.score[j];
ave = sum / (double)a.studentNum;
}
cout << "average : " << ave << endl;
}
}
int main()
{
course a[5] = {
{ "과목명1", 0, 0 },
{ "과목명2", 0, 0 },
{ "과목명3", 0, 0 },
{ "과목명4", 0, 0 },
{ "과목명5", 0, 0 },
};
ifstream fin("data.txt");
if (fin.fail()) {
cerr << "input file error"; return -1;
}
for (int i = 0; i < 5; i++)
process(fin, a[i]);
system("pause");
return 0;
}
#include <fstream>
using namespace std;
struct course {
char subject[64];
int studentNum;
int score[256];
};
void process(ifstream &fin, course &a)
{
int sum = 0;
double ave = 0;
fin >> a.subject;
if (!fin.eof()) {
cout << a.subject;
fin >> a.studentNum;
a.score = new int[a.studentNum];
for (int j = 0; j < a.studentNum; j++) {
fin >> a.score[j];
sum += a.score[j];
ave = sum / (double)a.studentNum;
}
cout << "average : " << ave << endl;
}
}
int main()
{
course a[5] = {
{ "과목명1", 0, 0 },
{ "과목명2", 0, 0 },
{ "과목명3", 0, 0 },
{ "과목명4", 0, 0 },
{ "과목명5", 0, 0 },
};
ifstream fin("data.txt");
if (fin.fail()) {
cerr << "input file error"; return -1;
}
for (int i = 0; i < 5; i++)
process(fin, a[i]);
system("pause");
return 0;
}
2주차 과제
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int sum = 0, num, sum1 = 0, number = 0;
double average = 0;
ofstream fout;
ifstream fin;
fin.open("data.txt");
fout.open("output.txt");
while (!fin.eof()) {
sum1 = sum;
fin >> num;
for (int i = 0; i < num; i++) {
fin >> number;
sum += number;
}
sum = sum - sum1;
average = (double)sum / num;
fout << "number of data : " << num << endl;
fout << "sum : " << sum << endl;
fout << "average : " << average << endl << endl;
}
fout.close();
fin.close();
return 0;
}
#include <fstream>
using namespace std;
int main() {
int sum = 0, num, sum1 = 0, number = 0;
double average = 0;
ofstream fout;
ifstream fin;
fin.open("data.txt");
fout.open("output.txt");
while (!fin.eof()) {
sum1 = sum;
fin >> num;
for (int i = 0; i < num; i++) {
fin >> number;
sum += number;
}
sum = sum - sum1;
average = (double)sum / num;
fout << "number of data : " << num << endl;
fout << "sum : " << sum << endl;
fout << "average : " << average << endl << endl;
}
fout.close();
fin.close();
return 0;
}
HTML
<body>
<table border = "1">
<tr>
<td width = "50%">
<ul>
<li>list 1</li>
<li>list2</li>
<li>list3</li>
</ul>
</td>
<td width = "50%">
<ul>
<li>list4</li>
<li>list5</li>
<li>list6</li>
</ul>
</td>
</tr>
<tr>
<td>
<p>Anything in table
</p>
</td>
<td>
<p> <img src = "cloud.jpg" alt = "cloud"/></p>
</td>
</tr>
</body>
=============================================================
<audio controls autoplay>
<source src = "old_pop.ogg" type = "audio/ogg">
<source src = "old_pop.wav" type = "audio/wav">
<source src = "old_pop.mp3" type = "audio/mp3">
</audio>
=============================================================
<video controls src = "movie.mp4" >
</video>
<video src = "movie.ogg" autoplay controls>
</video>
<video width = "640" height = "480" controls>
<source src = "trailer.ogv" type ='video/ogg'>
</video>
=============================================================
<body>
<iframe src "" name ="iframe1"></iframe>
<p><a href = "http://www.w3.org" target = "iframe1">www.web</a></p>
=============================================================
<body>
<div style = "border : 3px solid red;">
<h2>lion</h2>
<p>lion lives in Africa and has strong legs and chin,
<span style = "color : red;"> 긴 송곳니</span>
를 지니고 있다.
</p>
</body>
=============================================================
<body>
<form action = "input.jsp" method = "post">
<input type = "text" name = "Text" />
<input type = "password" name = "password" />
<input type = "radio" name = "radio" />
<input type = "checkbox" name = "fruits" value = "Apple" checked >Apple
<input type = "checkbox" name = "fruits" value = "grape">grape
<input type = "range" name = "range" min="0" max = "10" step ="2"/>
<input type = "file" name = "file" >
<input type = "Reset" name = "Reset">
<input type = "image" src = "submit.png" alt ="제출 버튼">
<button type = "submit"><img src = "submit.png"></button>
<input type = "hidden" name = "hidden">
<input type = "submit" name = "submit" value = "제출">
</form>
</body>
<table border = "1">
<tr>
<td width = "50%">
<ul>
<li>list 1</li>
<li>list2</li>
<li>list3</li>
</ul>
</td>
<td width = "50%">
<ul>
<li>list4</li>
<li>list5</li>
<li>list6</li>
</ul>
</td>
</tr>
<tr>
<td>
<p>Anything in table
</p>
</td>
<td>
<p> <img src = "cloud.jpg" alt = "cloud"/></p>
</td>
</tr>
</body>
=============================================================
<audio controls autoplay>
<source src = "old_pop.ogg" type = "audio/ogg">
<source src = "old_pop.wav" type = "audio/wav">
<source src = "old_pop.mp3" type = "audio/mp3">
</audio>
=============================================================
<video controls src = "movie.mp4" >
</video>
<video src = "movie.ogg" autoplay controls>
</video>
<video width = "640" height = "480" controls>
<source src = "trailer.ogv" type ='video/ogg'>
</video>
=============================================================
<body>
<iframe src "" name ="iframe1"></iframe>
<p><a href = "http://www.w3.org" target = "iframe1">www.web</a></p>
=============================================================
<body>
<div style = "border : 3px solid red;">
<h2>lion</h2>
<p>lion lives in Africa and has strong legs and chin,
<span style = "color : red;"> 긴 송곳니</span>
를 지니고 있다.
</p>
</body>
=============================================================
<body>
<form action = "input.jsp" method = "post">
<input type = "text" name = "Text" />
<input type = "password" name = "password" />
<input type = "radio" name = "radio" />
<input type = "checkbox" name = "fruits" value = "Apple" checked >Apple
<input type = "checkbox" name = "fruits" value = "grape">grape
<input type = "range" name = "range" min="0" max = "10" step ="2"/>
<input type = "file" name = "file" >
<input type = "Reset" name = "Reset">
<input type = "image" src = "submit.png" alt ="제출 버튼">
<button type = "submit"><img src = "submit.png"></button>
<input type = "hidden" name = "hidden">
<input type = "submit" name = "submit" value = "제출">
</form>
</body>
10.25.2017
10.25 C++
#include <iostream>
using namespace std;
class myvector{
private :
int *p;
int size;
int next;
public :
myvector(){
p = NULL, size = next = 0;
}
myvector(int n){
size = n;
p = new int[n];
next = 0;
}
myvector(int n, int v){
size = n;
p = new int[n];
next = n;
for(int i = 0; i < n; i++)
p[n] = v;
}
~myvector(){
if (p != NULL) delete[] p;
}
int get_size(){
return next;
}
int get_maxsize(){
return size;
}
int get_value(int i){
return p[i];
if(i <0 || i >= next){
cout << "index out of range" << endl;
return -1;
}
}
void set_value(int i , int v){
if(i < 0 || i >= next){
cout << "index out of range" << endl;
}
else p[i] = v;
}
void push_back(int v){
if (size == next){
if(p == NULL){
p = new int[10];
size = 10;
}
else
{
int *q = new int[size *2];
for(int i =0;i<size;i++){
q[i]=p[i];
}
delete[] p;
p = q;
size = size*2;
}
}
p[next++] = v;
}
void clear(){
delete[] p;
size = next = 0;
}
};
void read_data(myvector &m){
int value;
m.clear();
while(true){
cin >> value;
if(value < 0) break;
m.push_back(value);
}
}
void process(myvector &m){
int sum = 0;
for(int i = 0;i<m.get_size();i++){
sum += m.get_value(i);
}
cout << (double)sum / m.get_size() << endl;
}
int main(){
myvector a, b(20), c(16,100);
cout << a.get_maxsize() << "," << a.get_size() << endl;
cout << b.get_maxsize() << "," << b.get_size() << endl;
cout << c.get_maxsize() << "," << c.get_size() << endl;
read_data(a); process(a);
read_data(a); process(a);
return 0;
}
using namespace std;
class myvector{
private :
int *p;
int size;
int next;
public :
myvector(){
p = NULL, size = next = 0;
}
myvector(int n){
size = n;
p = new int[n];
next = 0;
}
myvector(int n, int v){
size = n;
p = new int[n];
next = n;
for(int i = 0; i < n; i++)
p[n] = v;
}
~myvector(){
if (p != NULL) delete[] p;
}
int get_size(){
return next;
}
int get_maxsize(){
return size;
}
int get_value(int i){
return p[i];
if(i <0 || i >= next){
cout << "index out of range" << endl;
return -1;
}
}
void set_value(int i , int v){
if(i < 0 || i >= next){
cout << "index out of range" << endl;
}
else p[i] = v;
}
void push_back(int v){
if (size == next){
if(p == NULL){
p = new int[10];
size = 10;
}
else
{
int *q = new int[size *2];
for(int i =0;i<size;i++){
q[i]=p[i];
}
delete[] p;
p = q;
size = size*2;
}
}
p[next++] = v;
}
void clear(){
delete[] p;
size = next = 0;
}
};
void read_data(myvector &m){
int value;
m.clear();
while(true){
cin >> value;
if(value < 0) break;
m.push_back(value);
}
}
void process(myvector &m){
int sum = 0;
for(int i = 0;i<m.get_size();i++){
sum += m.get_value(i);
}
cout << (double)sum / m.get_size() << endl;
}
int main(){
myvector a, b(20), c(16,100);
cout << a.get_maxsize() << "," << a.get_size() << endl;
cout << b.get_maxsize() << "," << b.get_size() << endl;
cout << c.get_maxsize() << "," << c.get_size() << endl;
read_data(a); process(a);
read_data(a); process(a);
return 0;
}
최종 완성본
#include <iostream>
using namespace std;
class myvector{
private :
int *p;
int size;
int next;
public :
myvector(){
p = NULL, size = next = 0;
}
myvector(int n){
size = n;
p = new int[n];
next = 0;
}
myvector(int n, int v){
size = n;
p = new int[n];
next = n;
for(int i = 0; i < n; i++)
p[n] = v;
}
~myvector(){
if (p != NULL) delete[] p;
}
int get_size(){
return next;
}
int get_maxsize(){
return size;
}
int get_value(int i){
return p[i];
if(i <0 || i >= next){
cout << "index out of range" << endl;
return -1;
}
}
void set_value(int i , int v){
if(i < 0 || i >= next){
cout << "index out of range" << endl;
}
else p[i] = v;
}
void push_back(int v){
if (size == next){
if(p == NULL){
p = new int[10];
size = 10;
}
else
{
int *q = new int[size *2];
for(int i =0;i<size;i++){
q[i]=p[i];
}
delete[] p;
p = q;
size = size*2;
}
}
p[next++] = v;
}
void clear(){
delete[] p;
size = next = 0;
}
};
void read_data(myvector &m){
int value;
m.clear();
while(true){
cin >> value;
if(value < 0) break;
m.push_back(value);
}
}
void process(myvector &m){
int sum = 0;
for(int i = 0;i<m.get_size();i++){
sum += m.get_value(i);
}
cout << (double)sum / m.get_size() << endl;
}
int main(){
myvector a, b(20), c(16,100);
cout << a.get_maxsize() << "," << a.get_size() << endl;
cout << b.get_maxsize() << "," << b.get_size() << endl;
cout << c.get_maxsize() << "," << c.get_size() << endl;
read_data(a); process(a);
read_data(a); process(a);
return 0;
}
using namespace std;
class myvector{
private :
int *p;
int size;
int next;
public :
myvector(){
p = NULL, size = next = 0;
}
myvector(int n){
size = n;
p = new int[n];
next = 0;
}
myvector(int n, int v){
size = n;
p = new int[n];
next = n;
for(int i = 0; i < n; i++)
p[n] = v;
}
~myvector(){
if (p != NULL) delete[] p;
}
int get_size(){
return next;
}
int get_maxsize(){
return size;
}
int get_value(int i){
return p[i];
if(i <0 || i >= next){
cout << "index out of range" << endl;
return -1;
}
}
void set_value(int i , int v){
if(i < 0 || i >= next){
cout << "index out of range" << endl;
}
else p[i] = v;
}
void push_back(int v){
if (size == next){
if(p == NULL){
p = new int[10];
size = 10;
}
else
{
int *q = new int[size *2];
for(int i =0;i<size;i++){
q[i]=p[i];
}
delete[] p;
p = q;
size = size*2;
}
}
p[next++] = v;
}
void clear(){
delete[] p;
size = next = 0;
}
};
void read_data(myvector &m){
int value;
m.clear();
while(true){
cin >> value;
if(value < 0) break;
m.push_back(value);
}
}
void process(myvector &m){
int sum = 0;
for(int i = 0;i<m.get_size();i++){
sum += m.get_value(i);
}
cout << (double)sum / m.get_size() << endl;
}
int main(){
myvector a, b(20), c(16,100);
cout << a.get_maxsize() << "," << a.get_size() << endl;
cout << b.get_maxsize() << "," << b.get_size() << endl;
cout << c.get_maxsize() << "," << c.get_size() << endl;
read_data(a); process(a);
read_data(a); process(a);
return 0;
}
10.24.2017
7주차 과제
<9-1>
#include <iostream>
using namespace std;
class CRectangle {
private :
double width, height;
public:
CRectangle() {
width = height = 1.0;
}
~CRectangle() {
}
CRectangle(double a, double b){
width = a, height = b;
}
double get_width() {
return width;
}
double get_height() {
return height;
}
void set_width(double a) {
width = a;
}
void set_height(double a) {
height = a;
}
double getArea() {
cout << "면적은 : " << width*height << endl;
return width*height;
}
double getPerimeter() {
cout << "둘레 길이는 : " << 2 * (width + height) << endl;
return 2 * (width + height);
}
};
int main() {
CRectangle a, b;
a.set_height(40);
a.set_width(4);
cout << "첫 번째 객체의 높이는 : " << a.get_height() << endl;
cout << "너비는 : " << a.get_width() << endl;
a.getArea();
a.getPerimeter();
b.set_height(35.9);
b.set_width(3.5);
cout << "두 번째 객체의 높이는 : " << b.get_height() << endl;
cout << "너비는 : " << b.get_width() << endl;
b.getArea();
b.getPerimeter();
system("pause");
return 0;
}
9-2
#include <iostream>
using namespace std;
class Fan {
private :
int speed;
bool on;
double radius;
public:
Fan() {
speed = 1;
on = false;
radius = 5;
}
Fan(int a, bool b, double c)
{
speed = a;
on = b;
radius = c;
}
~Fan() {
}
int get_speed() {
return speed;
}
bool get_on() {
return on;
}
double get_radius() {
return radius;
}
void set_speed(int a) {
speed = a;
}
void set_on(bool a) {
on = a;
}
void set_radius(double a) {
radius = a;
}
};
int main() {
Fan a, b;
a.set_speed(3);
a.set_on(true);
a.set_radius(10);
b.set_speed(2);
b.set_on(false);
b.set_radius(5);
cout << "Speed is : " << a.get_speed() << endl;
cout << "Is it on? (on : 1, if off : 0) : " << a.get_on() << endl;
cout << "Radius is : " << a.get_radius() << endl;
cout << "Speed is : " << b.get_speed() << endl;
cout << "Is it on? (on : 1, if off : 0) : " << b.get_on() << endl;
cout << "Radius is : " << b.get_radius() << endl;
system("pause");
return 0;
}
9-3
#include <iostream>
using namespace std;
class Account {
private :
int id;
double balance, annualInterestRate;
public :
Account() {
id = 0;
balance = annualInterestRate = 0.0;
}
Account() {
}
int get_id() {
return id;
}
double get_balance() {
return balance;
}
double get_annualInterestRate() {
return annualInterestRate;
}
void set_id(int a) {
id = a;
}
void set_balance(double a) {
balance = a;
}
void set_annualInterestRate(double a) {
annualInterestRate = a;
}
double getMonthlyInterestRate() {
return get_annualInterestRate() / 12;
}
double withdraw(double amount) {
return balance -= amount;
}
double deposit(double amount) {
return balance += amount;
}
};
int main() {
Account a;
a.set_id(1122);
a.set_balance(20000);
a.set_annualInterestRate(4.5);
a.withdraw(2500);
a.deposit(3000);
cout << "잔액 : " << a.get_balance() << endl;
cout << "월 이자 : " << a.get_balance()*a.getMonthlyInterestRate()/100 << endl;
system("pause");
return 0;
}
9-4
#include <iostream>
#include <cmath>
using namespace std;
class MyPoint {
private :
double x, y;
public :
MyPoint() {
x = y = 0.0;
}
MyPoint(double a, double b) {
x = a;
y = b;
}
~MyPoint() {
}
double get_x() {
return x;
}
double get_y() {
return y;
}
double distance(double a, double b) {
return sqrt(pow(a-x, 2) + pow(b-y,2));
}
};
int main() {
MyPoint a(0, 0.0);
MyPoint b(10, 30.5);
double distance = a.distance(b.get_x(), b.get_y());
cout << "두 점 사이의 거리는 : " << distance << endl;
system("pause");
return 0;
}
#include <iostream>
using namespace std;
class CRectangle {
private :
double width, height;
public:
CRectangle() {
width = height = 1.0;
}
~CRectangle() {
}
CRectangle(double a, double b){
width = a, height = b;
}
double get_width() {
return width;
}
double get_height() {
return height;
}
void set_width(double a) {
width = a;
}
void set_height(double a) {
height = a;
}
double getArea() {
cout << "면적은 : " << width*height << endl;
return width*height;
}
double getPerimeter() {
cout << "둘레 길이는 : " << 2 * (width + height) << endl;
return 2 * (width + height);
}
};
int main() {
CRectangle a, b;
a.set_height(40);
a.set_width(4);
cout << "첫 번째 객체의 높이는 : " << a.get_height() << endl;
cout << "너비는 : " << a.get_width() << endl;
a.getArea();
a.getPerimeter();
b.set_height(35.9);
b.set_width(3.5);
cout << "두 번째 객체의 높이는 : " << b.get_height() << endl;
cout << "너비는 : " << b.get_width() << endl;
b.getArea();
b.getPerimeter();
system("pause");
return 0;
}
9-2
#include <iostream>
using namespace std;
class Fan {
private :
int speed;
bool on;
double radius;
public:
Fan() {
speed = 1;
on = false;
radius = 5;
}
Fan(int a, bool b, double c)
{
speed = a;
on = b;
radius = c;
}
~Fan() {
}
int get_speed() {
return speed;
}
bool get_on() {
return on;
}
double get_radius() {
return radius;
}
void set_speed(int a) {
speed = a;
}
void set_on(bool a) {
on = a;
}
void set_radius(double a) {
radius = a;
}
};
int main() {
Fan a, b;
a.set_speed(3);
a.set_on(true);
a.set_radius(10);
b.set_speed(2);
b.set_on(false);
b.set_radius(5);
cout << "Speed is : " << a.get_speed() << endl;
cout << "Is it on? (on : 1, if off : 0) : " << a.get_on() << endl;
cout << "Radius is : " << a.get_radius() << endl;
cout << "Speed is : " << b.get_speed() << endl;
cout << "Is it on? (on : 1, if off : 0) : " << b.get_on() << endl;
cout << "Radius is : " << b.get_radius() << endl;
system("pause");
return 0;
}
9-3
#include <iostream>
using namespace std;
class Account {
private :
int id;
double balance, annualInterestRate;
public :
Account() {
id = 0;
balance = annualInterestRate = 0.0;
}
Account() {
}
int get_id() {
return id;
}
double get_balance() {
return balance;
}
double get_annualInterestRate() {
return annualInterestRate;
}
void set_id(int a) {
id = a;
}
void set_balance(double a) {
balance = a;
}
void set_annualInterestRate(double a) {
annualInterestRate = a;
}
double getMonthlyInterestRate() {
return get_annualInterestRate() / 12;
}
double withdraw(double amount) {
return balance -= amount;
}
double deposit(double amount) {
return balance += amount;
}
};
int main() {
Account a;
a.set_id(1122);
a.set_balance(20000);
a.set_annualInterestRate(4.5);
a.withdraw(2500);
a.deposit(3000);
cout << "잔액 : " << a.get_balance() << endl;
cout << "월 이자 : " << a.get_balance()*a.getMonthlyInterestRate()/100 << endl;
system("pause");
return 0;
}
9-4
#include <iostream>
#include <cmath>
using namespace std;
class MyPoint {
private :
double x, y;
public :
MyPoint() {
x = y = 0.0;
}
MyPoint(double a, double b) {
x = a;
y = b;
}
~MyPoint() {
}
double get_x() {
return x;
}
double get_y() {
return y;
}
double distance(double a, double b) {
return sqrt(pow(a-x, 2) + pow(b-y,2));
}
};
int main() {
MyPoint a(0, 0.0);
MyPoint b(10, 30.5);
double distance = a.distance(b.get_x(), b.get_y());
cout << "두 점 사이의 거리는 : " << distance << endl;
system("pause");
return 0;
}
9.20.2017
#include <iostream>
#include <fstream>
using namespace std;
int main() {
int num, sum = 0;
ofstream fout("out.txt");
ifstream fin("input.txt");
if (fin.fail() || fout.fail())
{
cerr << "파일 열기 에러" << endl;
return -1;
}
while (!fin.eof()) {
fin >> num;
if (fin.fail()) break;
sum += num;
}
fout.close();
fin.close();
system("pause");
return 0;
}
#include <iostream>
#include <fstream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
ofstream fout("C:\Users\IT333-27\Desktop\output.txt");
srand(time(0));
int num, sum = 0;
double average = 0;
int size = 5 + rand()%5;
for(int i = 0;i < size; i++){
int n = 10 + rand()%30;
cout << n << endl;
for(int j = 0; j< n ; j++){
fout << rand()%100 << " ";
}
fout << endl << endl;
}
/*average = (double)sum/num;
fout << "number of data" << num << endl;
fout << "sum : " << sum << endl;
fout << "average : " << average << endl;
fout.close();*/
return 0;
}
#include <fstream>
using namespace std;
int main() {
int num, sum = 0;
ofstream fout("out.txt");
ifstream fin("input.txt");
if (fin.fail() || fout.fail())
{
cerr << "파일 열기 에러" << endl;
return -1;
}
while (!fin.eof()) {
fin >> num;
if (fin.fail()) break;
sum += num;
}
fout.close();
fin.close();
system("pause");
return 0;
}
#include <iostream>
#include <fstream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main(){
ofstream fout("C:\Users\IT333-27\Desktop\output.txt");
srand(time(0));
int num, sum = 0;
double average = 0;
int size = 5 + rand()%5;
for(int i = 0;i < size; i++){
int n = 10 + rand()%30;
cout << n << endl;
for(int j = 0; j< n ; j++){
fout << rand()%100 << " ";
}
fout << endl << endl;
}
/*average = (double)sum/num;
fout << "number of data" << num << endl;
fout << "sum : " << sum << endl;
fout << "average : " << average << endl;
fout.close();*/
return 0;
}
9.08.2017
배열과 포인터
#include <iostream>
using namespace std;
double sum = 0;
double read_data(double *data, int size) {
for (int i = 3; i < size; i++) {
cin >> *data;
cout << *data;
sum += *data;
data++;
}
return sum;
}
int main() {
double data[5];
read_data(&data[3], 5);
cout << sum<< endl;
system("pause");
return 0;
}
9.06.2017
09.06 C++
#include <iostream>
using namespace std;
int main(){
//10개의 정수를 일어들여 배열에 저장, 합과 평균을 구하여 출력하기
int arr[10];
double average = 0;
int sum = 0;
cout << "숫자 10개 입력해주세요" << endl;
for(int i = 0;i<10;i++){
cin >> arr[i];
sum += arr[i];
}
average = (double )sum/10.0;
cout << sum << ", " << average << endl;
}
=====================================================================
#include <iostream>
using namespace std;
void read_data(int data[], int size){
//배열과 배열의 크기를 인자로 주고 이 배열에 정수를 읽어들여 저장한 후 return
cout << "숫자 10개 입력" << endl;
for(int i = 0;i<size;i++){
cin >> data[i];
}
}
int sum(int data[], int size){
//배열과 배열의 크기를 인자로 주고 이 배열에 저장된 숫자의 합을 구하여 return 하기
int sum = 0;
for(int i = 0; i < size;i ++){
sum += data[i];
}
cout << sum;
return sum;
}
int main(){
int arr[10];
read_data(arr, 10);
sum(arr, 10);
}
using namespace std;
int main(){
//10개의 정수를 일어들여 배열에 저장, 합과 평균을 구하여 출력하기
int arr[10];
double average = 0;
int sum = 0;
cout << "숫자 10개 입력해주세요" << endl;
for(int i = 0;i<10;i++){
cin >> arr[i];
sum += arr[i];
}
average = (double )sum/10.0;
cout << sum << ", " << average << endl;
}
=====================================================================
#include <iostream>
using namespace std;
void read_data(int data[], int size){
//배열과 배열의 크기를 인자로 주고 이 배열에 정수를 읽어들여 저장한 후 return
cout << "숫자 10개 입력" << endl;
for(int i = 0;i<size;i++){
cin >> data[i];
}
}
int sum(int data[], int size){
//배열과 배열의 크기를 인자로 주고 이 배열에 저장된 숫자의 합을 구하여 return 하기
int sum = 0;
for(int i = 0; i < size;i ++){
sum += data[i];
}
cout << sum;
return sum;
}
int main(){
int arr[10];
read_data(arr, 10);
sum(arr, 10);
}
8.29.2017
08.29 C++
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
using namespace std;
class Test {
char* name;
public:
Test() {
}
Test(char* p) {
name = p;
}
Test(const Test& p) {
name = new char[strlen(p.name) + 1];
strcpy(name, p.name);
}
void print() {
printf("%s \n", name);
}
};
void main() {
Test t1("Test1");
t1.print();
Test t2 = t1;
t2.print();
}
========================================================================
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
using namespace std;
class Student {
char* name, *studentNum;
int kor, math, eng;
public:
Student(char* n, char* stN, int k, int m, int e) {
name = n;
studentNum = stN;
kor = k;
math = m;
eng = e;
}
Student(const Student& s) {
name = new char[strlen(s.name) + 1];
strcpy(name, s.name);
studentNum = new char[strlen(s.studentNum) + 1];
strcpy(studentNum, s.studentNum);
kor = s.kor;
math = s.math;
eng = s.eng;
}
void show() {
cout << "이름은 : " << name << ", 학번은 : " << studentNum << ", 국어는 : " << kor <<
", 수학은 : " << math << ", 영어는 : " << eng << endl;
}
/*~Student() {
delete name;
delete studentNum;
}*/
};
void main() {
Student s1("이름", "2017", 8,9,10);
Student s2 = s1;
Student s3 = s1;
s1.show();
s2.show();
s3.show();
// delete , new : 동적할당 된 곳에서만 사용 가능
// delete s1;
}
#include <iostream>
#include <string>
using namespace std;
class Test {
char* name;
public:
Test() {
}
Test(char* p) {
name = p;
}
Test(const Test& p) {
name = new char[strlen(p.name) + 1];
strcpy(name, p.name);
}
void print() {
printf("%s \n", name);
}
};
void main() {
Test t1("Test1");
t1.print();
Test t2 = t1;
t2.print();
}
========================================================================
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
using namespace std;
class Student {
char* name, *studentNum;
int kor, math, eng;
public:
Student(char* n, char* stN, int k, int m, int e) {
name = n;
studentNum = stN;
kor = k;
math = m;
eng = e;
}
Student(const Student& s) {
name = new char[strlen(s.name) + 1];
strcpy(name, s.name);
studentNum = new char[strlen(s.studentNum) + 1];
strcpy(studentNum, s.studentNum);
kor = s.kor;
math = s.math;
eng = s.eng;
}
void show() {
cout << "이름은 : " << name << ", 학번은 : " << studentNum << ", 국어는 : " << kor <<
", 수학은 : " << math << ", 영어는 : " << eng << endl;
}
/*~Student() {
delete name;
delete studentNum;
}*/
};
void main() {
Student s1("이름", "2017", 8,9,10);
Student s2 = s1;
Student s3 = s1;
s1.show();
s2.show();
s3.show();
// delete , new : 동적할당 된 곳에서만 사용 가능
// delete s1;
}
8.26.2017
선택정렬
#include <stdio.h>
void main() {
/*
정렬 : 선택정렬, 버블정렬, 퀵정렬
선택정렬 : 최고 낮은 값을 찾아서 앞에서부터 차례대로 쌓아주는 기법
*/
int arr[] = { 5,72,3,1,92,7,25,19,13 };
int min; //낮은 값을 갖는 변수
int min_index; //낮은 값의 위치(인덱스)
for (int i = 0; i < sizeof(arr) / sizeof(int); i++) {
printf("%d ", arr[i]);
}printf("\n");
for (int i = 0; i < sizeof(arr) / sizeof(int) - 1; i++) {
//기준값을 잡을 반복문
min = arr[i];
min_index = i;
for (int k = i + 1; k < sizeof(arr) / sizeof(int); k++) {
//가장 낮은 값을 찾기 위한 반복문
if (arr[k] < min) {
min = arr[k];
min_index = k;
}
}//end for(k)
arr[min_index] = arr[i];
arr[i] = min;
}
for (int i = 0; i < sizeof(arr) / sizeof(int); i++) {
printf("%d ", arr[i]);
}printf("\n");
}
void main() {
/*
정렬 : 선택정렬, 버블정렬, 퀵정렬
선택정렬 : 최고 낮은 값을 찾아서 앞에서부터 차례대로 쌓아주는 기법
*/
int arr[] = { 5,72,3,1,92,7,25,19,13 };
int min; //낮은 값을 갖는 변수
int min_index; //낮은 값의 위치(인덱스)
for (int i = 0; i < sizeof(arr) / sizeof(int); i++) {
printf("%d ", arr[i]);
}printf("\n");
for (int i = 0; i < sizeof(arr) / sizeof(int) - 1; i++) {
//기준값을 잡을 반복문
min = arr[i];
min_index = i;
for (int k = i + 1; k < sizeof(arr) / sizeof(int); k++) {
//가장 낮은 값을 찾기 위한 반복문
if (arr[k] < min) {
min = arr[k];
min_index = k;
}
}//end for(k)
arr[min_index] = arr[i];
arr[i] = min;
}
for (int i = 0; i < sizeof(arr) / sizeof(int); i++) {
printf("%d ", arr[i]);
}printf("\n");
}
doublyLinkedList 자료구조
#include <stdio.h>
#include <stdlib.h>
typedef struct Test{
int data;
struct Test* next; //다음노드의 주소
struct Test* prev; //이전 노드의 주소
}test;
void main() {
test* head = (test*)malloc(sizeof(test));
test* tail = (test*)malloc(sizeof(test));
head->next = tail;
tail->prev = head;
test* newnode1 = (test*)malloc(sizeof(test));
newnode1->next = tail;
tail->prev = newnode1;
head->next = newnode1;
newnode1->prev = head;
test* newnode2 = (test*)malloc(sizeof(test));
newnode2->next = tail;
tail->prev = newnode2;
newnode1->next = newnode2;
newnode2->prev = newnode1;
test* newnode3 = (test*)malloc(sizeof(test));
newnode3->next = tail;
tail->prev = newnode3;
newnode2->next = newnode3;
newnode3->prev = newnode2;
newnode1->data = 10;
newnode2->data = 20;
newnode3->data = 30;
test* move = head->next;
test* move2 = tail->prev;
while (move != tail) {
printf("%d", move->data);
move = move->next;
}printf("\n"); // 출력
while (move2 != head) {
printf("%d", move2->data);
move2 = move2->prev;
} printf("\n");
}
========================================================================
//함수 이용하기
#include <stdio.h>
#include <stdlib.h>
typedef struct Test{
int data;
struct Test* next; //다음노드의 주소
struct Test* prev; //이전 노드의 주소
}test;
void input(test* head, int a) {
test* newnode = (test*)malloc(sizeof(test));
newnode->next = head->next;
head->next->prev = newnode;
head->next = newnode;
newnode->prev = head;
newnode->data = a;
}
void del_Node(test* head, test* tail, int b) {
test* move = head->next;
while (move != tail) {
if (move->data == b) {
move = move->next;
move->next->next->prev = move->next->prev;
free(move);
break;
}
}
}
void main() {
int del;
test* head = (test*)malloc(sizeof(test));
test* tail = (test*)malloc(sizeof(test));
head->next = tail;
tail->prev = head;
input(head, 10);
input(head, 20);
input(head, 30);
input(head, 40);
input(head, 50);
printf("입력\n");
scanf("%d", &del);
del_Node(head, tail, del);
test* move = head->next;
while (move != tail) {
printf("%d ", move->data);
move = move->next;
}printf("\n");
}
#include <stdlib.h>
typedef struct Test{
int data;
struct Test* next; //다음노드의 주소
struct Test* prev; //이전 노드의 주소
}test;
void main() {
test* head = (test*)malloc(sizeof(test));
test* tail = (test*)malloc(sizeof(test));
head->next = tail;
tail->prev = head;
test* newnode1 = (test*)malloc(sizeof(test));
newnode1->next = tail;
tail->prev = newnode1;
head->next = newnode1;
newnode1->prev = head;
test* newnode2 = (test*)malloc(sizeof(test));
newnode2->next = tail;
tail->prev = newnode2;
newnode1->next = newnode2;
newnode2->prev = newnode1;
test* newnode3 = (test*)malloc(sizeof(test));
newnode3->next = tail;
tail->prev = newnode3;
newnode2->next = newnode3;
newnode3->prev = newnode2;
newnode1->data = 10;
newnode2->data = 20;
newnode3->data = 30;
test* move = head->next;
test* move2 = tail->prev;
while (move != tail) {
printf("%d", move->data);
move = move->next;
}printf("\n"); // 출력
while (move2 != head) {
printf("%d", move2->data);
move2 = move2->prev;
} printf("\n");
}
========================================================================
//함수 이용하기
#include <stdio.h>
#include <stdlib.h>
typedef struct Test{
int data;
struct Test* next; //다음노드의 주소
struct Test* prev; //이전 노드의 주소
}test;
void input(test* head, int a) {
test* newnode = (test*)malloc(sizeof(test));
newnode->next = head->next;
head->next->prev = newnode;
head->next = newnode;
newnode->prev = head;
newnode->data = a;
}
void del_Node(test* head, test* tail, int b) {
test* move = head->next;
while (move != tail) {
if (move->data == b) {
move = move->next;
move->next->next->prev = move->next->prev;
free(move);
break;
}
}
}
void main() {
int del;
test* head = (test*)malloc(sizeof(test));
test* tail = (test*)malloc(sizeof(test));
head->next = tail;
tail->prev = head;
input(head, 10);
input(head, 20);
input(head, 30);
input(head, 40);
input(head, 50);
printf("입력\n");
scanf("%d", &del);
del_Node(head, tail, del);
test* move = head->next;
while (move != tail) {
printf("%d ", move->data);
move = move->next;
}printf("\n");
}
8.24.2017
08.24 C++
#include <iostream>
#include <string>
using namespace std;
class Human{
public:
string name;
int age;
public:
Human(){
cout << "이름과 나이를 입력하시오.\n";
cin >> name;
cin >> age;
}
string returnName() {
return name;
}
void print() {
cout << "이름은 : " << name << "나이는 : " << age << endl;
}
};
class Student : public Human {
int korean, math, english;
public:
void s_input() {
cout << "학생의 국어, 수학, 영어 점수를 입력하시오." << endl;
cin >> korean >> math >> english;
}
void printStudent(){
print();
cout << "국어 점수 : " << korean << ", 수학 점수 : " << math << ", 영어 점수 : " << english << endl;
}
};
class Teacher : public Human {
Student* s[3];
int index;
public:
Teacher() {
index = 0;
}
void addStudent(Student* p) {
if (index > 2) {
cout << "학생 추가 불가" << endl;
return;
}
s[index] = p;
index++;
void printTeacher(){
print();
for (int i = 0; i < index; i++)
s[i]->printStudent();
}
};
void main() {
Student* s[10];
Teacher* t[3];
string name;
int input = 0, i = 0, j = 0;
while (input != 6) {
cout << "[menu]\n1.학생추가 2.선생님추가 3.학생출력 4.선생님정보출력 5. 선생님의 학생 추가 6.종료" << endl;
cin >> input;
if (input == 1) {
s[i] = new Student();
s[i] -> s_input();
i++;
}
else if (input == 2) {
cout << "관리할 학생의 이름을 입력해주세요." << endl;
cin >> name;
for (int k = 0; k < i; k++) {
if (name == s[k]->returnName()) { // (*s[k]).returnName()
t[j] = new Teacher();
t[j]->addStudent(s[k]);
j++;
break;
}
}
}
else if (input == 3) {
for (int p = 0; p < i; p++) {
s[p]->printStudent();
}
}
else if (input == 4) {
//선생님의 이름, 나이, 학생명단출력
for (int q = 0; q < j; q++) {
t[q]->printTeacher();
}
}
else if (input == 5) {
cout << "어느 선생님을 바꾸실건가요?" << endl;
cin >> name;
for (int u = 0; u < j; u++) {
if (name == t[u]->returnName()) {
cout << "학생 이름 입력해주세요." << endl;
cin >> name;
for (int k = 0; k < i; k++){
if (name == s[k]->returnName())
t[u]->addStudent(s[k]);
}
}
}
}
}
}
===========================================================================================
#include <iostream>
#include <string>
using namespace std;
class Score {
int kor, math, eng;
string name;
public:
Score(int a, int b, int c, string d) {
kor = 0;
math = 0;
eng = 0;
name = d;
}
void change_value() (int p, int q, int r) {
kor = p;
math = q;
eng = r;
}
void change_value(string a) {
name = a;
}
void printOut() {
cout << "국어 점수는 : " << kor << "수학 점수는 : " << math << "영어 점수는 : " << eng << "\n이름은 : " << name << endl;
}
};
void main(){
int input = 0, score1, score2, score3;
string name;
Score s(12, 13, 14, "점수");
while (input != 4) {
cout << "[menu]\n1.점수 변경 2.이름변경 3.모두 출력 4.종료" << endl;
cin >> input;
if (input == 1) {
cout << "변경할 점수를 입력해주세요." << endl;
cin >> score1 >> score2 >> score3;
s.change_value(score1, score2, score3);
}
else if (input == 2) {
cout << "변경할 이름을 입력해주세요." << endl;
cin >> name;
s.change_value(name);
}
else if (input == 3) {
s.printOut();
}
}
}
===========================================================================================
#include <iostream>
#include <string>
using namespace std;
class hamburger {
protected :
string name;
int price, number;
public:
/*
hamburger(string name, int price, int number) {
this->name = name;
this->price = price;
this->number = number;
}
*/
void show_info() {
cout << name << price << number;
}
};
class Set_menu :public hamburger{
public:
Set_menu(string name, int price, int number)// : hamburger(name, price, number) {
this->name = name;
this->price = price;
this->number = number;
}
// overriding
void show_info() {
cout << name << price - 500 << number;
}
};
void main() {
Set_menu s1("불고기", 2000, 5);
s1.show_info();
}
#include <string>
using namespace std;
class Human{
public:
string name;
int age;
public:
Human(){
cout << "이름과 나이를 입력하시오.\n";
cin >> name;
cin >> age;
}
string returnName() {
return name;
}
void print() {
cout << "이름은 : " << name << "나이는 : " << age << endl;
}
};
class Student : public Human {
int korean, math, english;
public:
void s_input() {
cout << "학생의 국어, 수학, 영어 점수를 입력하시오." << endl;
cin >> korean >> math >> english;
}
void printStudent(){
print();
cout << "국어 점수 : " << korean << ", 수학 점수 : " << math << ", 영어 점수 : " << english << endl;
}
};
class Teacher : public Human {
Student* s[3];
int index;
public:
Teacher() {
index = 0;
}
void addStudent(Student* p) {
if (index > 2) {
cout << "학생 추가 불가" << endl;
return;
}
s[index] = p;
index++;
void printTeacher(){
print();
for (int i = 0; i < index; i++)
s[i]->printStudent();
}
};
void main() {
Student* s[10];
Teacher* t[3];
string name;
int input = 0, i = 0, j = 0;
while (input != 6) {
cout << "[menu]\n1.학생추가 2.선생님추가 3.학생출력 4.선생님정보출력 5. 선생님의 학생 추가 6.종료" << endl;
cin >> input;
if (input == 1) {
s[i] = new Student();
s[i] -> s_input();
i++;
}
else if (input == 2) {
cout << "관리할 학생의 이름을 입력해주세요." << endl;
cin >> name;
for (int k = 0; k < i; k++) {
if (name == s[k]->returnName()) { // (*s[k]).returnName()
t[j] = new Teacher();
t[j]->addStudent(s[k]);
j++;
break;
}
}
}
else if (input == 3) {
for (int p = 0; p < i; p++) {
s[p]->printStudent();
}
}
else if (input == 4) {
//선생님의 이름, 나이, 학생명단출력
for (int q = 0; q < j; q++) {
t[q]->printTeacher();
}
}
else if (input == 5) {
cout << "어느 선생님을 바꾸실건가요?" << endl;
cin >> name;
for (int u = 0; u < j; u++) {
if (name == t[u]->returnName()) {
cout << "학생 이름 입력해주세요." << endl;
cin >> name;
for (int k = 0; k < i; k++){
if (name == s[k]->returnName())
t[u]->addStudent(s[k]);
}
}
}
}
}
}
===========================================================================================
#include <iostream>
#include <string>
using namespace std;
class Score {
int kor, math, eng;
string name;
public:
Score(int a, int b, int c, string d) {
kor = 0;
math = 0;
eng = 0;
name = d;
}
void change_value() (int p, int q, int r) {
kor = p;
math = q;
eng = r;
}
void change_value(string a) {
name = a;
}
void printOut() {
cout << "국어 점수는 : " << kor << "수학 점수는 : " << math << "영어 점수는 : " << eng << "\n이름은 : " << name << endl;
}
};
void main(){
int input = 0, score1, score2, score3;
string name;
Score s(12, 13, 14, "점수");
while (input != 4) {
cout << "[menu]\n1.점수 변경 2.이름변경 3.모두 출력 4.종료" << endl;
cin >> input;
if (input == 1) {
cout << "변경할 점수를 입력해주세요." << endl;
cin >> score1 >> score2 >> score3;
s.change_value(score1, score2, score3);
}
else if (input == 2) {
cout << "변경할 이름을 입력해주세요." << endl;
cin >> name;
s.change_value(name);
}
else if (input == 3) {
s.printOut();
}
}
}
===========================================================================================
#include <string>
using namespace std;
class hamburger {
protected :
string name;
int price, number;
public:
/*
hamburger(string name, int price, int number) {
this->name = name;
this->price = price;
this->number = number;
}
*/
void show_info() {
cout << name << price << number;
}
};
class Set_menu :public hamburger{
public:
Set_menu(string name, int price, int number)// : hamburger(name, price, number) {
this->name = name;
this->price = price;
this->number = number;
}
// overriding
void show_info() {
cout << name << price - 500 << number;
}
};
void main() {
Set_menu s1("불고기", 2000, 5);
s1.show_info();
}
피드 구독하기:
글 (Atom)