结构化编程与面向对象编程
案例
全员育人导师制案例信息技术应用案例心得信息技术教学案例综合实践活动案例我余额宝案例
音乐播放器**************定乐一歌曲乐~程序乐行乐序播放~歌曲乐中可以包含不同格式的文个清清
件;如~,MP3WAV
void main()
{
定乐一字符串乐~存放音乐文件名个数String[] songs = new String[MAX]; //
彩虹songs[0] = new String(“c:\.wav”);
天路songs[1] = new String(“d:\.mp3”);
乐儿响叮当songs[2] = new String(“c:\.wav”);
……
playMusic(songs);
}
void playMusic(String[] list){
按乐序播放fot(int i=0; i
方法
快递客服问题件处理详细方法山木方法pdf计算方法pdf华与华方法下载八字理论方法下载
改造后,
abstract class Song
{
音乐名称protected string title; //
音乐乐乐protected int duration; //
Song(string t) {
title = t;
}
abstract void play();
}
public class Mp3 extends Song{
Mp3(string t) { super(t); duration=…… }
void play() { …….}
}
public class Wav extends Song {
Wav(string t) { super(t); duration=……}
void play() { …….}
}
public class PlayList
{
乐目集合private Vector Songs; //
public PlayList() { Songs = new Vector(); }
添加乐目public void add(Song t) //
{
Songs.addElement(t);
}
播放全部的乐目public void playAll() //
{
Enumeration enum = Songs.elements();
while (enum.hasMoreElements())
((Song) enum.nextElement()).play();
}
}
public static void main(string[] args){
PlayList list = new PlayList();
彩虹list.add(new Mp3(“c:\.mp3”));
天路list.add(new Mp3(“d:\.wav”));
乐儿响叮当list.add(new Wav(“c:\.wav”));
list.playAll();
}
借乐程序****************乐化的借乐程序,构
void lendBook(string bookID, string readerID)
{
乐乐者是否已借乐乐bool borrowFlag = isBorrowed(readerID, bookID); //
乐乐乐者借乐量数int borrowedNum = getBorrowedAmount(readerID); //
if(borrowFlag)
你已乐借乐了此乐提示已借此乐 messageBox.show(""); //
else if(borrowedNum>=5)
您已乐借乐了本乐提示乐者借乐已限乐达 messageBox.show("5"); //
else
{
乐乐某本乐的在架量数 int amount = getStockAmount(bookID); //
有乐存 if(amount>0) //
{
某乐的在架量数减 updateStock(bookID, amount-1);//1
保存借乐乐乐 saveLoan(bookID, readerID);//
}
else
乐乐已全部借出 messageBox.show("");
}
}
面向乐象的借乐程序,
Class Book { }
Class Reader { }
Class Loan { }
void lendBook(string bookID, string readerID)
{
Book b1 = new Book(bookID);
Reader r1 = new Reader(readerID);
乐乐者是否已借乐乐if(r1.isBorrowed(bookID)) //
你已乐借乐了此乐提示已借此乐 messageBox.show(""); //
乐乐乐者借乐量数else if(r1.getBorrowedAmount()>=5)//
您已乐借乐了本乐提示乐者借乐已限乐达 messageBox.show("5"); //
else
{
乐乐某本乐的在架量数 int amount = b1.getStockAmount(); //
有乐存 if(amount>0) //
{
某乐的在架量数减 b1.updateStock(amount-1);//1
Loan l1 = new Loan(b1, r1);
保存借乐乐乐 l1.save();//
}
else
乐乐已全部借出 messageBox.show("");
}
}
*********乐*********乐化程序乐乐构
#define STACK_SIZE 128
struct myStack
{
int stack[STACK_SIZE];
int top;
};
void initStack(myStack s) {
s.top = 0;
}
bool isEmpty(myStack s){
Return( (s.top==0) );
}
bool push(int item, myStack s) {
if (s.top == STACK_SIZE) return False;
s.stack[s.top++] = item;
return True;
}
bool pop(int &item, myStack s) {
if (s.top == 0) return False;
item = s.stack[--s.top];
return True;
}
面向乐象程序乐乐,
乐的元素乐型乐 template // Tclass Stack {
乐的算集运public: //
乐乐空乐void clear();//
入乐~成功乐返回~否乐返回假真bool push(const T item); // item
返回乐乐容乐出~成功返回~否乐返回假内并真bool pop(T & item);//
返回乐乐容不乐出~成功返回~否乐返回假内真bool top(T& item);//
若乐已空返回真bool isEmpty(; //
若乐已乐返回真bool isFull(); //
};
template class arrStack : public Stack {
乐的乐序存乐private: //
乐中最多可存放的元素个数int mSize;//
乐乐位置~乐小于inttop;// mSize
存放乐元素的乐数T *st;//
乐的算的乐序乐乐运public: //
乐建一乐定乐度的乐序乐乐例个arrStack(int size) { //
mSize = size;
top = -1;
st = new T[mSize];
}
乐建一乐序乐的乐例 个arrStack() { //
top = -1;
}
析函构数~arrStack() {//
delete [] st;
}
清内空乐容void clear() {//
top = -1;
}
bool arrStack::push(const T item) {
乐已乐 if (top == mSize-1) { //
乐乐溢出 cout << "" << endl;
return false;
}
新元素入乐修改乐乐指乐并else {//
st[++top] = item;
return true;
}
}
出乐的乐序乐乐bool arrStack::pop(T & item) {//
乐乐空if (top == -1) {//
乐乐空~不能乐行出乐操作 cout << ""<< endl;
return false;
}
else {
返回乐乐元素修改乐乐指乐并 item = st[top--];//
return true;
}
}
返回乐乐容~但不乐出内bool arrStack:: top(T & item) {//
乐空if (top == -1) {//
乐乐空~不能乐取乐乐元素 cout << " "<< endl;
return false;
}
else {
item = st[top];
return true;
}
}
把乐空清void arrStack::clear() {//
top = -1;
}
乐乐乐~返回非零乐;乐真,bool arrStack:: isFull() {//true
return (top == maxsize-1) ;}