Rise In Logo



Build on Stellar

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

  • Define Customer and Product Structures:
  • Define structures (structs) to represent customers and products.
  • Create a structure for each customer containing information such as name, surname, and balance.
  • Create a structure for each product containing information such as name, price, and stock quantity.
  • Create Market Functions:
  • Implement functions to perform basic market operations such as adding customers, adding products, and making purchases.
  • Include a function to allow customers to purchase a specific product by checking their balances.
  • Develop the Main Program:
  • Instantiate sample customers and products.
  • Create a loop to provide a user interface for customers to perform market operations.

Checklist

  • Define and create customer and product structures.
  • Implement market functions and test each one.
  • Write and execute the main program.
  • Provide a user interface for customers to perform market operations.

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.");

    }

}

Project

Comments

Anonymous

0/500

You need to enroll in the course to be able to comment!

Stay in the know

Never miss updates on new programs and opportunities.

Rise In Logo

Rise together in web3!