#include #include #include #include #include #include using namespace std; struct Node{ string frame; Node* next; Node* prev; }; typedef Node* NodePtr; void append_frame(NodePtr &Head, NodePtr &Rear, string nframe); //append a frame node to the doubly link list, used in load_tape() function void load_tape(NodePtr &Head, string filename); //load a movie text file to the memory and store in doubly link list void play_forward(NodePtr &ptr); //play forward a frame void play_backward(NodePtr &ptr); //play backward a frame void copy_frame(NodePtr &ptr); //duplicate the current frame pointed to by ptr void delete_frame(NodePtr &Head, NodePtr &ptr); //delete the current frame pointed to by ptr void stop(NodePtr Head, NodePtr &ptr); //stops the player and moves ptr back to Head void start_104player(NodePtr &Head); //movie player control void erase_tape(NodePtr &Head); //free the memory void menu(); //player menu void main(){ NodePtr Head = NULL; string filename; cout << "input filename: "; cin >> filename; load_tape(Head, filename); start_104player(Head); erase_tape(Head); } //this function is given to the students void start_104player(NodePtr &Head){ NodePtr ptr = Head; char input = 's'; int time = 100; //control playback speed do{ if (kbhit()) input = getch(); switch(input){ case 'f': system("cls"); play_forward(ptr); menu(); Sleep(time); break; case 'b': system("cls"); play_backward(ptr); menu(); Sleep(time); break; case 's': system("cls"); stop(Head, ptr); menu(); input = ' '; break; case 'p': input = ' '; break; case 'd': system("cls"); delete_frame(Head, ptr); menu(); input = ' '; break; case 'c': copy_frame(ptr); input = ' '; break; } }while(input != 'x'); } //this function is given to the students void menu(){ cout << "press f for forward\n" << "press b for backward\n" << "press p for pause\n" << "press s for stop\n" << "press d for delete current frame\n" << "press c for copy current frame\n" << "press x to exit\n"; } //this function is given to the students void load_tape(NodePtr &Head, string filename){ string nframe = ""; char c; NodePtr Rear = NULL; ifstream fin(filename.c_str()); while(!fin.eof()){ nframe = ""; for(int i=0; i<14; i++){ do{ c = fin.get(); if(fin.eof()) return; nframe+=c; }while(c != '\n'); } //append a frame node to the doubly link list; you have to implement this function yourself append_frame(Head, Rear, nframe); } fin.close(); }