Array Customer Order Instances

Source: Internet
Author: User

Order class

////Order.h#import<Foundation/Foundation.h>#import "Customer.h"@interfaceOrder:nsobject@property (nonatomic)intoid; @property (nonatomic,strong) NSString*Name: @property (nonatomic,strong) Customer*customer;@end////ORDER.M#import "Order.h"@implementationOrder-(nsstring*) description{return[NSString stringWithFormat:@"%d,%@", _oid,_name];}@end

Customer class

////Customer.h#import<Foundation/Foundation.h>@interfaceCustomer:nsobject@propertyintCID; @property (nonatomic,strong) NSString*Name: @property (nonatomic,strong) NSString*Email: @property (nonatomic,strong) NSString*address;@end////CUSTOMER.M#import "Customer.h"@implementationCustomer-(nsstring*) description{return[NSString stringWithFormat:@"%d,%@,%@,%@", _cid,_name,_email,_address];}@end

Manage customer and order classes

////CustomerAndOrderManager.h//array of customer orders////Created by MAC on 15/12/15.//copyright©2015 year MAC. All rights reserved.//#import<Foundation/Foundation.h>#import "Customer.h"#import "Order.h"@interfaceCustomerandordermanager:nsobject@property (nonatomic,strong) Nsmutablearray*customerlist, @property (nonatomic,strong) Nsmutablearray*orderlist;//1. Managing Customers-(void) Addcustomer: (customer*) C;-(void) DeleteCustomer: (customer*) C;-(customer*) Getcustomerbyid: (int) Cid1;-(void) Listcustomer;//2. Manage Orders-(void) AddOrder: (order*) O;-(void) Deleteorder: (order*) O;-(nsarray*) Getorderbycustomer: (customer*) C;-(void) Listorder;@end////CUSTOMERANDORDERMANAGER.M//array of customer orders////Created by MAC on 15/12/15.//copyright©2015 year MAC. All rights reserved.//#import "CustomerAndOrderManager.h"@implementationCustomerandordermanager-(instancetype) init{if(self=[Super Init]) {Self.customerlist= [Nsmutablearray arraywithcapacity:Ten]; Self.orderlist= [Nsmutablearray arraywithcapacity:Ten]; }    returnSelf ;}//1. Managing Customers-(void) Addcustomer: (customer*) c{[self.customerlist addobject:c];}-(void) DeleteCustomer: (customer*) c{[self.customerlist removeobject:c];}-(customer*) Getcustomerbyid: (int) cid1{ for(Customer *cinchself.customerlist) {if(c.cid==cid1) {            returnC; }    }    returnNil;}-(void) listcustomer{ for(Customer *cinchself.customerlist) {NSLog (@"%@", c); }}//2. Manage Orders-(void) AddOrder: (order*) o{[self.orderlist addobject:o];}-(void) Deleteorder: (order*) o{[self.orderlist removeobject:o];}-(nsarray*) Getorderbycustomer: (customer*) c{Nsmutablearray*a =[[Nsmutablearray alloc]init];  for(Order *oinchself.orderlist) {if(o.customer==c)        {[a addobject:o]; }    }    returnA;}-(void) listorder{ for(Order *oinchself.orderlist) {NSLog (@"%@", O); }}@end

The implementation class. m

////main.m//array of customer orders////Created by MAC on 15/12/15.//copyright©2015 year MAC. All rights reserved.//#import<Foundation/Foundation.h>#import "Order.h"#import "Customer.h"#import "CustomerAndOrderManager.h"intMainintargcConst Char*argv[]) {@autoreleasepool {Customer*C1 =[Customer Alloc]init]; Customer*C2 =[Customer Alloc]init]; Customer*C3 =[Customer Alloc]init]; Order*o1 =[[Order alloc]init]; Order*o2 =[[Order alloc]init]; Order*o3 =[[Order alloc]init]; Customerandordermanager*a =[[Customerandordermanager alloc]init]; C1.cid= -; C1.name=@"Xiaowang"; C1.email=@"[email protected]"; C1.address=@"625"; //Add to Customer list[a addcustomer:c1]; C2.cid= -; C2.name=@"Xiaohei"; C2.email=@"[email protected]"; C2.address=@"624"; //Add to Customer list[a addcustomer:c2]; C3.cid= A; C3.name=@"Xiaobai"; C3.email=@"[email protected]"; C3.address=@"623"; //Add to Customer list[a addcustomer:c3]; O1.customer=C1; O1.oid=1001; O1.name=@"Shampoo"; //Add to order list[a addorder:o1]; O2.customer=C2; O2.oid=1002; O2.name=@"Washing Powder"; //Add to order list[a addorder:o2]; O3.customer=C1; O3.oid=1005; O3.name=@"Washingpowder";        [A ADDORDER:O3]; //Traverse all orders and customers[a listcustomer];        [A listorder]; //Query CID for 20 of customer informationCustomer *c=[a Getcustomerbyid: -]; NSLog (@"%@", c);//        //Delete Customer//[a deletecustomer:c1];//[a listcustomer];NSLog (@"------------"); //Check all orders from CustomersNsarray *array =[a getorderbycustomer:c1]; NSLog (@"%@", array);        [A DELETEORDER:O3];                                            [A listorder]; }    return 0;}

Array Customer Order Instances

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.