Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.49 KB | None | 0 0
  1. //ANH PHÙNG
  2.  
  3. import UIKit
  4.  
  5. struct Product {
  6.    
  7.     var name: String
  8.    
  9.     var price: Double
  10.    
  11.     var tax : Double
  12.    
  13.     var taximport : Double
  14.    
  15.     init(name: String, price: Double, tax: Double, taximport: Double) {
  16.        
  17.         self.name = name
  18.        
  19.         self.price = price
  20.        
  21.         self.tax = tax
  22.  
  23.         self.taximport = taximport
  24.  
  25.     }
  26.    
  27. }
  28.  
  29. class ViewController: UIViewController {
  30.  
  31.     var arOrder1: [Product] = []
  32.     var arOrder2: [Product] = []
  33.     var arOrder3: [Product] = []
  34.    
  35.     override func viewDidLoad() {
  36.         super.viewDidLoad()
  37.        
  38.         arOrder1 = [
  39.             Product(name: "book", price: 12.49, tax: 0, taximport: 0),
  40.             Product(name: "music cd", price: 14.99, tax: 1.499, taximport: 0),
  41.             Product(name: "chocolate bar", price: 0.85, tax: 0, taximport: 0)]
  42.            
  43.         arOrder2 = [
  44.             Product(name: "imported box of chocolates", price: 10, tax: 0, taximport: 0.5),
  45.             Product(name: "imported bottle of perfume", price: 47.5, tax: 4.75, taximport: 2.375)]
  46.            
  47.         arOrder3  = [
  48.             Product(name: "imported bottle of perfume", price: 27.99, tax: 2.799, taximport: 1.399),
  49.             Product(name: "bottle of perfume", price: 18.99, tax: 1.899, taximport: 0),
  50.             Product(name: "packet of headache pills", price: 9.75, tax: 0, taximport: 0),
  51.             Product(name: "imported box of chocolates", price: 11.25, tax: 0, taximport: 0.5625)]
  52.            
  53.            
  54.        
  55.        
  56.        
  57.         print("-----Output order 1--------------------")
  58.         var saletax1 = 0.0
  59.         var total1 = 0.0
  60.         for i in 0..<arOrder1.count {
  61.             let price = arOrder1[i].price + arOrder1[i].tax + arOrder1[i].taximport
  62.             total1 += price
  63.             let tax = arOrder1[i].tax + arOrder1[i].taximport
  64.             saletax1 += tax
  65.             print("\(arOrder1[i].name),\(price)")
  66.             //print("Sales Taxes: \(saletax1)")
  67.         }
  68.         print("Sales Taxes: \(saletax1)")
  69.         print("Total:  \(total1)")
  70.        
  71.        
  72.        
  73.        
  74.        
  75.         print("-----Output order 2--------------------")
  76.         var saletax2 = 0.0
  77.         var total2 = 0.0
  78.         for i in 0..<arOrder2.count {
  79.             let price = arOrder2[i].price + arOrder2[i].tax + arOrder2[i].taximport
  80.             total2 += price
  81.             let tax = arOrder2[i].tax + arOrder2[i].taximport
  82.             saletax2 += tax
  83.             print("\(arOrder2[i].name),\(price)")
  84.            
  85.         }
  86.         print("Sales Taxes: \(saletax2)")
  87.         print("Total:  \(total2)")
  88.  
  89.        
  90.         print("-----Output order 3--------------------")
  91.         var saletax3 = 0.0
  92.         var total3 = 0.0
  93.         for i in 0..<arOrder3.count {
  94.             let price = arOrder3[i].price + arOrder3[i].tax + arOrder3[i].taximport
  95.             total3 += price
  96.             let tax = arOrder3[i].tax + arOrder3[i].taximport
  97.             saletax3 += tax
  98.             print("\(arOrder3[i].name),\(price)")
  99.             //print("Sales Taxes: \(saletax1)")
  100.         }
  101.         print("Sales Taxes: \(saletax3)")
  102.         print("Total:  \(total3)")
  103.  
  104.        
  105.        
  106.         // Do any additional setup after loading the view, typically from a nib.
  107.     }
  108.  
  109.     override func didReceiveMemoryWarning() {
  110.         super.didReceiveMemoryWarning()
  111.         // Dispose of any resources that can be recreated.
  112.     }
  113.  
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement