Odak modu
Task Details
In this homework, you will create a simulation of a market system. This system will include customers and products, and provide an interface for customers to perform certain actions.
Steps
Checklist
Code Template
struct Customer {
// Complete the struct according to the requested parameters
}
struct Product {
// Complete the struct according to the requested parameters
}
// Market functions
impl Customer {
// Function for purchasing a product
fn buy_product(&mut self, product: &mut Product, quantity: u32) -> bool {
//If the product is available in sufficient quantity in stock and the customer has enough balance to buy it, purchase the product and update the customer's balance. Return true if the purchase is successful, false otherwise.
}
}
// Main program
fn main() {
let mut customer1 = Customer {
// Create sample customers
};
let mut customer2 = Customer {
// Create sample customers
};
let mut product = Product {
// Create a sample product
};
// Customers' product purchase operations
println!("Customer 1 is buying a product...");
if [customer1.buy](http://customer1.buy)_product(&mut product, 3) {
println!("Customer 1 successfully purchased the product.");
} else {
println!("Customer 1 couldn't purchase the product.");
}
println!("Customer 2 is buying a product...");
if [customer2.buy](http://customer2.buy)_product(&mut product, 8) {
println!("Customer 2 successfully purchased the product.");
} else {
println!("Customer 2 couldn't purchase the product.");
}
}
Yazılım Kariyerinde İlerlemeni Hızlandıracak Programlar
Patika+ programlarımız ile 4-8 aylık yoğun yazılım kamplarına katıl, temel bilgilerden başlayarak kapsamlı bilgiler edin, yazılım kariyerine başla!
Yorum yapabilmek için derse kayıt olmalısın!