视频中老师视频讲过,自己再次重新写的。有老师课里边的内容,也有原创。全部自己敲出来的
mian.h
- #import <Foundation/Foundation.h>
- #import "Cinema.h"
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- Cinema *C1=[[Cinema alloc]initWithcinema:@"搞基圣地"];
- printf("**************************************\n");
- printf("******欢迎使用基佬专用电影票购票系统*******\n");
- printf("**************************************\n");
- while (1) {
- printf("是否开始购票?\n1.是 0.否\n");
- int flag;
- scanf("%d",&flag);
- if (flag==1) {
- [C1 printmovie];
- }else if (flag==0){
- break;
- }else{
- printf("输入有误!\n");
- }
- }
- printf("谢谢您的使用\n");
- }
- return 0;
- }
复制代码 Cinema.h
- #import <Foundation/Foundation.h>
- #import "MovieTicket.h"
- @interface Cinema : NSObject
- {
- NSString *_cinema;
- MovieTicket *_movt[5];
- }
- //初始化init
- -(instancetype)initWithcinema:(NSString*)name;
- //列出电影播放安排
- -(void)printmovie;
- //选择电影
- -(void)chosemovie;
- //选择座位
- -(void)choseseat;
- //选择第几排
- -(void)chosepai;
- //选择第几列
- -(void)choselie;
- //确认位置
- -(void)queren;
- //支付
- -(void)pay;
- //出票
- -(void)printticket;
- @end
复制代码
Cinema.m
- #import "Cinema.h"
- int NOMBER;
- int PAI,LIE;
- @implementation Cinema
- //初始化init
- -(instancetype)initWithcinema:(NSString*)name{
- if (self=[super init]) {
- _cinema=name; //MovieTicket *_mt[5]
- for (int i=0; i<5; i++) {
- MovieTicket *mt=[MovieTicket new];
- mt.name=@"放映电影";
- mt.place=name;
- mt.starttime=[NSString stringWithFormat:@"%02d:00",i+1];
- mt.duration=@"120min";
- mt.no=i+1;
- mt.moviename=[NSString stringWithFormat:@"精肛互撸娃%02d",i+1];
- mt.director=@"激情四射狼";
- mt.actor=@"bigbaby";
- mt.price=100;
- _movt[i]=mt;
- }
- }
- return self;
- }
- //列出电影播放安排
- -(void)printmovie{
- for (int i=0; i<5; i++) {
- NSLog(@"\n\nNO.%d\n电影名:%@ \n导演:%@ 主演:%@ \n电影时长:%@ 开场时间:%@ \n票价:%.2f\n\n",_movt[i].no,_movt[i].moviename,_movt[i].director,_movt[i].actor,_movt[i].duration,_movt[i].starttime,_movt[i].price);
- };
- [self chosemovie];
- }
- //选择电影
- -(void)chosemovie{
- printf("请选择电影编号!\n");
- scanf("%d",&NOMBER);
- if (NOMBER>0&&NOMBER<6) {
- NSLog(@"\n\n您已成功选择:%@",_movt[NOMBER-1].moviename);
- [self choseseat];
- }else {
- printf("输入非法,请重新选择!\n");
- [self chosemovie];
- };
- }
- //选择座位
- -(void)choseseat{
- printf("座位信息如下,'+'为可选座位,'-'为已售出座位\n");
- for (int i=-1; i<15; i++) {
- for (int j=-1; j<15; j++) {
- if (i==-1) {
- printf(" %02d ",j+1);
- }else if (j==-1){
- printf(" %02d ",i+1);
- }else{
- if (_movt[NOMBER]->_seat[i][j]==0) {
- printf(" + ");
- }else if(_movt[NOMBER]->_seat[i][j]==1){
- printf(" - ");
- }
- }
- }
- printf("\n");
- }
- [self chosepai];
- }
- //选择第几排
- -(void)chosepai{
- printf("请选择第几排\n");
- scanf("%d",&PAI);
- if (PAI>0&&PAI<16) {
- _movt[NOMBER-1].pai=PAI;
- printf("您已成功选择第%d排\n",PAI);
- [self choselie];
- }else{
- printf("输入非法,请重新选择!\n");
- [self chosemovie];
- };
- }
- //选择第几列
- -(void)choselie{
- printf("请选择第几列\n");
- scanf("%d",&LIE);
- if (LIE>0&&LIE<16) {
- _movt[NOMBER-1].lie=LIE;
- printf("您已成功选择第%d列\n",LIE);
- [self queren];
- }else{
- printf("输入非法,请重新选择!\n");
- [self choselie];
- };
-
- }
- //确认位置
- -(void)queren{
- int i;
- printf("您选择的是:第%d排,第%d列\n确认:1 取消:0\n",_movt[NOMBER-1].pai,_movt[NOMBER-1].lie);
- scanf("%d",&i);
- if (i==1) {
- _movt[NOMBER]->_seat[_movt[NOMBER-1].pai-1][_movt[NOMBER-1].lie-1]=1;
- printf("确认成功!\n");
- [self pay];
- }else if (i==0){
- printf("取消成功,程序即将退出。。。\n");
- return;
- }else {
- printf("输入非法,请重新选择!\n");
- [self queren];
- }
- }
- //支付
- -(void)pay{
- printf("支付中。。。。\n");
- printf("支付成功\n");
- [self printticket];
- }
- //出票
- -(void)printticket{
-
- NSLog(@"\n您的票:\n\n电影名:%@ \n导演:%@ 主演:%@ \n电影时长:%@ 开场时间:%@ \n票价:%.2f\n第%d排,第%d列\n\n",_movt[NOMBER-1].moviename,_movt[NOMBER-1].director,_movt[NOMBER-1].actor,_movt[NOMBER-1].duration,_movt[NOMBER-1].starttime,_movt[NOMBER-1].price,_movt[NOMBER-1].pai,_movt[NOMBER-1].lie);
- }
- @end
复制代码
Common.h
- #import <Foundation/Foundation.h>
- @interface Common : NSObject
- {
- @public
复制代码
Common.m
- #import "Common.h"
- @implementation Common
- @end
复制代码
Ticket.h
- #import "Common.h"
- @interface Ticket : Common
- //开始时间
- @property NSString *starttime;
- //持续时间
- @property NSString *duration;
- //座位位置
- @property int pai;
- @property int lie;
- @end
复制代码- #import "Ticket.h"
- @implementation Ticket
- @end
复制代码
MovieTicket.h
- #import "Ticket.h"
- @interface MovieTicket : Ticket
- //编号
- @property int no;
- //电影名
- @property NSString *moviename;
- //导演
- @property NSString *director;
- //主演
- @property NSString *actor;
- //票价
- @property float price;
- //打印票
- -(void)printMovieTicket;
- @end
复制代码
MovieTicket.m
- #import "MovieTicket.h"
- @implementation MovieTicket
- -(void)printMovieTicket{
- NSLog(@"打印票信息");
- }
- @end
复制代码
|
|