Software Engineering mvc junit
Software Engineering mvc junit
(mvc)
Name: Taha Dar
Roll No: Fa23-Bce-095
2. View
Definition: The View is responsible for displaying the data
and user interface.
Role in Online Shopping Cart:
o Presents cart data to the user, such as item lists, prices,
and total cost.
o Provides an interface for user interactions like adding or
removing items.
o Reflects real-time updates from the Model.
Examples:
o Displaying a table of items in the cart.
o Showing the total price and checkout button.
o Error messages like "Item out of stock."
3. Controller
Definition: The Controller acts as a mediator
between the Model and the View, handling user input
and updating data or UI accordingly.
Role in Online Shopping Cart:
o Processes user actions such as adding or
removing items.
o Communicates with the Model to update data.
o Requests the View to refresh with updated
information.
Examples:
o Handling a button click to add an item to the
cart.
o Removing an item when the user clicks
"Remove."
o Directing the View to display an error if an action
fails.
FLOW CHART OF MVC IN ONLINE SHOPPING CART
Start -> User Action (e.g., Add Item to Cart)
|
v
Controller Receives Input
|
v
Updates the Model (e.g., Add Item to Data Store)
|
v
Model Notifies Changes
|
v
View Fetches Updated Data from Model
|
v
Updated Cart Displayed to User
|
v
End
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
class CartItem {
public:
std::string name;
double price;
int quantity;
};
class ShoppingCartModel {
private:
std::vector<CartItem> cartItems;
public:
if (item.name == name) {
return;
cartItems.erase(std::remove_if(cartItems.begin(), cartItems.end(),
cartItems.end());
double total = 0;
return total;
return cartItems;
};
class ShoppingCartView {
public:
};
class ShoppingCartController {
private:
ShoppingCartModel model;
ShoppingCartView view;
public:
updateView();
model.removeItem(name);
updateView();
}
void updateView() {
view.displayCart(model.getItems(), total);
};
int main() {
ShoppingCartController controller;
controller.removeItem("Headphones");
return 0;