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

bato_3 #15

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
83 changes: 44 additions & 39 deletions bato_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,76 @@

class Csample{
public:
Csample(){ //iniitialization
Csample(){ //配列の初期化
for(int i=0;i<1000;i++){
stack[i]=-1;
}
}
void push(int x); //enter
int get(int cat); //arrey's public
int eget(); //element's public
int pop(); //back

void input_elements(int push_index); //配列要素の追加の定義
int application_array(int display_index); //配列の一般化の定義
int get_index(); //要素数表示の定義
int back_vale(); //値を戻すの定義
void display();//表示の定義


private:
int stack[1000];
int end_index=0;
};

/*enter*/
void Csample::push(int x){
stack[end_index]=x; //sub + element plus
/*配列要素の追加*/
void Csample::input_elements(int push_index){
stack[end_index]=push_index; //外側の値入力
end_index++;
}

/*arrey's public*/
int Csample::get(int cat){
return stack[cat];
/*配列の一般化*/
int Csample::application_array(int display_index){
return stack[display_index];
}
/*element's public*/
int Csample::eget(){

/*要素数の一般化*/
int Csample::get_index(){

return end_index;
}

/*back*/
int Csample::pop(){
int re=0; //return arrey;
re=stack[end_index - 1]; //plus-1 is display
stack[end_index -1]=-1;
end_index--;
/*値を戻す*/
int Csample::back_vale(){
int re=0; //初期化
re=stack[end_index - 1]; //こぴー(値を+してるので-1)
stack[end_index -1]=-1; //要素の初期化
end_index--;//要素数を減らす
return re;
}
void Csample::display(){
for(int i=0;i<end_index;i++){
std::cout<<stack[i]<<",";
}
std::cout<<std::endl;
}
int main(){
Csample cs1;
int a;
char q; //div
std::cin>>q; //div sub
while(q!='q'){
switch(q){
case 'i': //input
std::cin>>a; //num sub
cs1.push(a);
for(int i=0;i<cs1.eget();i++){
std::cout<<cs1.get(i)<<",";
}
std::cout<<std::endl;
int num;
char juging;
std::cin>>juging; // 操作の入力
while(juging!='q'){
switch(juging){
case 'i': //inputであれば
std::cin>>num; //数字入力
cs1.input_elements(num);//numの値を要素に加える
cs1.display();//表示
break;
case 'o': //return outpot
std::cout<<"return:"<<cs1.pop()<<std::endl;
for(int i=0;i<cs1.eget();i++){
std::cout<<cs1.get(i)<<",";
}
std::cout<<std::endl;
case 'o': //outputであれば
std::cout<<"return:"<<cs1.back_vale()<<std::endl;
cs1.display();//表示
break;

default: //i or o other
default: //どちらでもない
std::cout<<"error"<<std::endl;
}
std::cin>>q; //div sub
std::cin>>juging; //操作の入力
}
return 0;
}
Expand Down
57 changes: 57 additions & 0 deletions bato_3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include<iostream>
class sample{
public:
/*要素数の決定&初期化*/
sample(int push_index){
determine_elements = push_index; //値渡し
array = new int[push_index];//要素決定
}
~sample(){
delete[] array; //開放
}
int& access(int access_elements); //値の参照の定義
void display();//表示の定義
int get_index();//値の定義

private:
int *array; //配列ポインタ
int determine_elements;//入力した要素

};

/*値の参照*/
int& sample::access(int access_elements){
return array[access_elements];
}

/*値*/
int sample::get_index(){
return determine_elements;
}
/*配列表示*/
void sample::display(){
for(int i=0;i<determine_elements;i++){
std::cout<<array[i]<<",";
}
std::cout<<std::endl;
}

int main(){
int a;//入力
std::cout<<"要素数の決定:";
std::cin>>a;
sample s1(a);//インスタンス化1
s1.access(1)=25;//代入1

sample s2(a);//インスタンス化2
/*自由入力*/
for(int i=0;i<s2.get_index();i++){
int input;
std::cin>>input;
s2.access(i)= input;
}
s1.display();//s1表示
s2.display();//s2表示
return 0;

}
67 changes: 67 additions & 0 deletions bato_4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include<iostream>
#include<vector>

class sample{
public:
void front(){ //配列の一番目の要素を表示
v.begin();
}
void back(){ //配列の最後の要素を表示する
v.end();
}
void push(int last_index){//配列の最後に要素を追加する
v.push_back(last_index);
}
void incread_index(){
v.push_back(0);
}

void pop(){//配列の最初を消す。
v.erase(v.begin());
}
void display();
void empty(){
std::cout<<v.empty()<<std::endl;
}
void input_index();//入力方法


private:
std::vector<int> v{0,0,0,0,0};
};


//配列表示
void sample::display(){
std::cout<<"{";
for(unsigned int i=0;i<v.size();i++){
std::cout<<v[i]<<",";
}
std::cout<<"}"<<std::endl;
}
void sample::input_index(){//入力方法
unsigned int i=0;
int a=0;

while(a!=-1){
if(i<v.size()){
std::cin>>a;
v[i] = a;
}else{
pop();
incread_index();
std::cin>>a;
v[4] = a;
}
if(a!=-1){
display();
}
i++;
}
}
int main(){
sample s1;
s1.input_index();
s1.empty();
return 0;
}