#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);
}
10.31.2017
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;
}
피드 구독하기:
글 (Atom)