The implementation of the iOS shopping cart

Source: Internet
Author: User

#import<Foundation/Foundation.h>StaticNSString *ConstKeyproductid =@"productId";//Product IDStaticNSString *ConstKeyproductprice =@"Productprice";//Commodity priceStaticNSString *ConstKeyproductname =@"ProductName";//Product NameStaticNSString *ConstKeyproductamount =@"Productamount";//Number of goods intMainintargcConst Char*argv[]) {@autoreleasepool {/** * The 1th question please replace the date of birth of your Social Security number with *, and output (ex: 210304******2248) * PS: Requires a maximum of 3 lines of code in addition to printing,*/NSLog (@"---------------The first question-------------"); NSString*str=@"210212199411033517"; NSString*STR2 = [str stringbyreplacingoccurrencesofstring:@"19941103"Withstring:@"******"]; NSLog (@"%@", STR2); /** Question 2nd ShoppingCart the product data stored in the shopping cart, please merge the same goods and export the combined product name, quantity, unit price, total*/Nsarray*shoppingcart = @[@{keyproductid:@"A1001", Keyproductname:@"IPod5", keyproductprice:@1488.0, keyproductamount:@1}, @{keyproductid:@"A1003", Keyproductname:@"IPhone6", keyproductprice:@4488.0, keyproductamount:@1}, @{keyproductid:@"A1001", Keyproductname:@"IPod5", keyproductprice:@1488.0, keyproductamount:@1}, @{keyproductid:@"A1002", Keyproductname:@"iphone6s", keyproductprice:@5288.0, keyproductamount:@1}, @{keyproductid:@"A1003", Keyproductname:@"IPhone6", keyproductprice:@4488.0, keyproductamount:@1}, @{keyproductid:@"A1001", Keyproductname:@"IPod5", keyproductprice:@1488.0, keyproductamount:@1}]; NSLog (@"---------------The second question-------------"); Nsmutablearray*newarr=[[Nsmutablearray Alloc]initwitharray:shoppingcart]; intnum1=0, num2=0, num3=0; //NUM1 is the number of Ipod5, num2 is the number of iphone6s num3 the number of IPhone6                         for(Nsdictionary *dicinchnewarr) {            if([Dic[keyproductname] IsEqual:@"IPod5"]) {NUM1++; }            Else if([Dic[keyproductname] IsEqual:@"iphone6s"]) {num2++; }            Else if([Dic[keyproductname] IsEqual:@"IPhone6"]) {num3++; }} Nsset*Set=[Nsset Setwitharray:newarr];  for(Nsdictionary *dicinch Set){            intCount=[Dic[keyproductprice] intvalue]; if([Dic[keyproductname] IsEqual:@"IPod5"]) {NSLog (@"Item Number:%@ Product Name:%@ Quantity:%d Price:%@ total:%d", Dic[keyproductid], dic[keyproductname],num1,dic[keyproductprice],num1*count);} Else if([Dic[keyproductname] IsEqual:@"iphone6s"]) {NSLog (@"Item Number:%@ Product Name:%@ Quantity:%d Price:%@ total:%d", dic[keyproductid],dic[keyproductname],num2,dic[keyproductprice],num2*count); }                        Else if([Dic[keyproductname] IsEqual:@"IPhone6"]) {NSLog (@"Item Number:%@ Product Name:%@ Quantity:%d Price:%@ total:%d", dic[keyproductid],dic[keyproductname],num3,dic[keyproductprice],num3*count); }        }     }    return 0;}

The implementation of the iOS shopping cart

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.