Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

level1_1-6 #27

Open
wants to merge 29 commits into
base: master
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
30 changes: 30 additions & 0 deletions P01_runningletter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<stdio.h>
#include<windows.h>
#define SPACE 50

void show(char *pos);

int main()
{
char pos[102] = { " " };

for(int i=0;i<100;i++)
{
pos[i] = 'R';
show(pos);
pos[i] = ' ';
if(i==99) //字母碰到边界时变为递减
for(;i>=0;i--)
{
pos[i] = 'R';
show(pos);
pos[i] = ' ';
}
}
return 0;
}
void show(char *pos) {
printf("%s", pos);
Sleep(SPACE);
system("cls");
}
39 changes: 39 additions & 0 deletions P02_isprime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include<stdio.h>
#include<stdlib.h>
int IS(int); //判断是否为素数

int main() {
int x;

printf("输入一个正整数,程序判断它是否为素数(q to quit):");
while (scanf_s("%d", &x))
{
if (x == 1 || x == 2)
{
puts("是素数");
}
else if (IS(x))
puts("是素数.");
else puts("不是素数.");
printf("输入一个正整数,程序判断它是否为素数(q to quit):");
}
system("pause");
return 0;
}
int IS(int x)
{
int i;
int mark = 0; //创建标记

for (i = 2; i < x; i++)
{
if (x%i == 0)
{
mark = 1; //若被整除,标记mark为1
break;
}
}
if (mark == 1)
return 0;
else return 1;
}
38 changes: 38 additions & 0 deletions Stack/Stack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<iostream>
#include"Stack.h"

using namespace std;

void Stack::push(int item)
{
this->item[pos] = item;
pos++;
}

void Stack::pop()
{
cout << "pop " << item[pos-1]<<endl ;
pos--;
}

int Stack::IsFull()
{
return pos == n;
}

int Stack::IsEmpty()
{
return pos == 0;
}

void Stack::show()
{
for (int i = 0; i < pos; i++)
cout << item[i];
cout << endl;
}

Stack::Stack()
{
pos = 0;
}
20 changes: 20 additions & 0 deletions Stack/Stack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef STACK_H_
#define STACK_H_

#define n 100

class Stack
{
private:
int item[n];
int pos ;
public:
void push(int item);
void pop();
int IsFull();
int IsEmpty();
void show();
Stack();
};

#endif
42 changes: 42 additions & 0 deletions Stack/p02_Stack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<iostream>
#include"Stack.h"

using namespace std;

void main()
{
Stack s;

char ch;

while (1)
{
cin >> ch;
switch (ch)
{
case'p':
if (!s.IsFull())
{
cout << "push: ";
int tem;
cin >> tem;
s.push(tem);
}
else cout << "Full";
break;
case'o':
if (!s.IsEmpty())
{
s.pop();
}
else cout << "Empty";
break;
case's':
if(!s.IsEmpty())
s.show();
else cout << "Empty" << endl;
break;
}

}
}
73 changes: 73 additions & 0 deletions cpp/Clock/Clock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include"Clock.h"
#include<iostream>
#include<time.h>
#include<Windows.h>

void Clock::SetTime(int h, int m,int s)
{
this->h = h;
this->m = m;
this->s = s;
}

void Clock::operate()
{


using namespace std;

time_t t1, t2;
t1 = clock();

int ds, dm, dh;
time_t delta_t;

while (1)
{
Sleep(500);
t2 = clock();

delta_t = (t2 - t1) / CLOCKS_PER_SEC;

ps = (s + delta_t) % 60;
pm = ((s + delta_t) / 60 + m) % 60;
ph = ((((s + delta_t) / 60) + m) / 60 + h) % 24;

to_xy(10, 10);

cout.width(2);
cout << ph << ":";
cout.width(2);
cout << pm << ":";
cout.width(2);
cout<< ps;



}
}

void AlarmClock::SetAlarm(int h, int m, int s, bool alarm)
{
ah = h;
am = m;
as = s;
this->alarm = alarm;
}
void AlarmClock::Alarm()
{
if ((ah == h&&am == m&&as == s) && alarm == true)
{
puts("AAAAAAAA");
}
}

void to_xy(int x, int y) //��ָ������
{
HANDLE hout;
COORD coord;
coord.X = x;
coord.Y = y;
hout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout, coord);
}
33 changes: 33 additions & 0 deletions cpp/Clock/Clock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef CLOCK_H_
#define CLOCK_H_

class Clock
{
private:
int h, m, s; //��ʼʱ��
int ps, pm, ph; //��ǰʱ��
public:
friend class AlarmClock;
Clock(int h, int m, int s) { this->h = h; this->m = m; this->s = s; ps = s; pm = m; ph = h; }
void SetTime(int h, int m,int s);
void operate();
};

class AlarmClock :public Clock
{
private:
int ah;
int am;
int as;
bool alarm;

public:
friend class Clock;
AlarmClock(int h, int m, int s) :Clock(h, m, s) { alarm = false; }
void SetAlarm(int h, int m, int s,bool alarm);
void Alarm();
};

void to_xy(int x, int y);

#endif
10 changes: 10 additions & 0 deletions cpp/Clock/mian.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<iostream>
#include"Clock.h"


void main()
{
AlarmClock aclock(11, 8, 20);
aclock.SetAlarm(12, 0, 0, 0);
aclock.operate();
}
54 changes: 54 additions & 0 deletions cpp/p01_Queue/Queue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include<iostream>
#include"Queue.h"
#define WIDTH 100

using namespace std;

void Queue::append(int item)
{


rear++;
if (rear == WIDTH + 1) rear = 0;
this->item[rear] = item;




}
void Queue::pop()
{
cout << item[front + 1] << "pop" << endl;

front++;
if (front == WIDTH + 1) front = 0;



}

int Queue::IsFull()
{
int temp;
rear == WIDTH ? temp = -1 : temp = rear;
return (temp + 1) == front;
}

int Queue::IsEmpty()
{
return rear == front;
}

void Queue::show()
{
for (int i = front + 1; i != rear + 1; i++) //i为当前访问的item
{
if (i > WIDTH) i = 0; //处理front在数组尾情况,此时i不对应item,将i设为0指向数组首端

cout << item[i];

if (i == WIDTH && rear != WIDTH) //处理rear在数组尾情况
i = -1;

}
}
21 changes: 21 additions & 0 deletions cpp/p01_Queue/Queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef Queue_H_
#define Queue_H_

#define WIDTH 100

class Queue
{
private:
int item[WIDTH + 1];
int front = 0; //front+1是队列首元
int rear = 0;

public:
void append(int item);
void pop();
int IsFull();
int IsEmpty();
void show();
};

#endif
Loading