Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

2,3,4,5_kanbe_submit #13

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions kanbe_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
using namespace std;

class Stack{
public:
Stack(){
for(int i = 0; i < num_of_element; i++){
num[i] = -1;
}
}
void push(int x){
num[end_index] = x;
end_index++;
return;
}
void pop(){
cout << num[end_index - 1] << endl;
num[end_index - 1] = -1;
end_index--;
return;
}
void check(){
for(int i = 0; i < end_index; i++){
cout << num[i] << endl;
}

}
private:
int num[1000];
int num_of_element = 1000;
int end_index = 0;
};

int main(){
Stack obj;
for(int i=0; i<5; i++){
obj.push(i);
}
obj.push(666);
obj.check();
obj.pop();
}
33 changes: 33 additions & 0 deletions kanbe_3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <iostream>
using namespace std;

class sample {
public:
sample(int x){
hoge = new int[x];
}
~sample(){
delete[] hoge;
}

int &access(int num) {
int &ref = hoge[num-1];
return ref;
}

void vale_check(){
for(int i=0; i<5; i++){
cout << hoge[i] << endl;
}
}

private:
int *hoge;
};

int main() {
sample work(5);
int &change_ref = work.access(2);
change_ref = 100;
work.vale_check();
}
50 changes: 50 additions & 0 deletions kanbe_4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<iostream>
#include<vector>
class queue
{
public:
int front() {
return qv[0];
}

int back() {
return qv[qv.size()-1];
}

void push(int p_num) {
qv.push_back(p_num);
}

void pop() {
qv.erase(qv.begin());
}

void empty() {
std::cout << qv.size() << std::endl;
}
void call(){
for(int i=0; i<qv.size(); ++i){
std::cout << qv[i];
}
std::cout << std::endl;
}
private:
std::vector<int> qv;
};

int main() {
queue Que;
for(int i=0; i<10; ++i){
Que.push(i);
Que.call();
}

for(int i=0; i<10; ++i){
Que.pop();
Que.call();
}

Que.empty();

return 0;
}
49 changes: 49 additions & 0 deletions kanbe_5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include<iostream>
#include<vector>
using namespace std;

class sample{
private:
vector<int> vec1;
vector<int> vec2;
vector<int> vec_sum;


public:
sample(){
for(int i=1; i<4; i++){
vec1.push_back(i);
}
for(int i=4; i<7; i++){
vec2.push_back(i);
}
for(int i=0; i<3; i++){
vec_sum.push_back(0);
}
}
void ans_of_CrossProduct(){
int a=1,b=0;
for(int i=0; i<3; i++){
vec_sum[i] = vec1[i+a]*vec2[2-b-i] -vec1[2-b-i]*vec2[i+a];
if(i==0)
b=1;
if(i==1){
a=-2;
b=-1;
}
}
}

void ans_show(){
for(int i=0; i<3; i++)
cout << vec_sum[i] << endl;
}

};

int main(){
sample obj;
obj.ans_of_CrossProduct();
obj.ans_show();
return 0;
}