QHE5701 SQL

Java Python QHE5701 – Database Systems 2024
Lab – 5 1
Lab 5: Designing Database and Generating sample data (using data generator tool)
In this lab you’ll use MySQL to design and implement a database from user requirement.

Database Specification Details:
In a company that manages a big chain of doughnut-selling shops, there is a need to
create a database for the data accumulated through the last years. Consider that the data
you have available is:
• List of menus which can be regular or seasonal (for example Christmas menu),
they have a name and start and end date in case of a seasonal menu. Additionally,
we also have a specific colour palette they must follow used by each menu.

• List of products available for each menu we know names, prices, calories, sugar
content, protein, and salt.

• For the same sales, we know the buyer if they have scanned their loyalty app. A
buyer has some data saved like first name, last name, gender, age and occupation.

• Employees can have diTerent contracts (full-time, part-time) with additional total
working hours (overti QHE5701、SQL me). We also account for the years of experience of every one
of them.

• The branch is a location of our company that has an address and a size. Size is an
index that describes how big is the branch.

• List of ingredients used for every product (name, country of origin, units
purchased, price, name of the supplier)

• Each sale must be stored with the exact time and date of sale and price.

NOTE: Assume that size is a parameter denoting roughly the cost of running that branch.

Task:
Design a database for this problem, which involves:
i) Create an ER model for this problem
ii) Perform the mapping to the logical model QHE5701 – Database Systems 2024
Lab – 5 2
iii) Produce the SQL code for the database
iv) Create sample data for your database (to make it easier use a generator
like: https://extendsclass.com/csv-generator.html )

Lab Submission Guidelines:
Complete the task in Lab-5 as this will also be used in next lab. Details on Week-3
submission will be provided with Lab-6 description         

为了编写这样的程序,假设你已经有一个txt文件,其中的第一列存储了时间(shijian),第二列存储了值(qhe)。我们可以使用C++的标准库`fstream`来逐行读取数据,并将其分别存储在两个数组中。下面是一个简单的示例: ```cpp #include <iostream> #include <fstream> #include <vector> // 用于动态大小的数组 std::vector<std::string> shijian; // 存放时间字符串 std::vector<int> qhe; // 存放数值 int main() { std::ifstream inputFile("input.txt"); // 假设输入文件名为input.txt if (!inputFile.is_open()) { // 检查文件是否成功打开 std::cerr << "Failed to open the file!" << std::endl; return 1; } std::string line; while (std::getline(inputFile, line)) { // 逐行读取 size_t pos = 0; // 位置标记 int value; // 分割每行,提取第一列时间和第二列值 std::string column1 = line.substr(0, line.find(',')); // 提取到第一个逗号前的位置 std::istringstream iss(column1); // 创建istringstream来解析字符串 if (!(iss >> column1)) { std::cerr << "Invalid format for time!" << std::endl; continue; } shijian.push_back(column1); pos = line.find(',') + 1; // 移动到第二个逗号之后的位置 if ((pos == std::string::npos) || iss.fail()) { // 如果找不到第二个逗号或解析失败 std::cerr << "Invalid format for value!" << std::endl; continue; } iss >> value; // 解析值并存储到整数变量中 qhe.push_back(value); } inputFile.close(); // 关闭文件 // 打印结果供检查 for (size_t i = 0; i < shijian.size(); ++i) { std::cout << "Shijian[" << i << "]: " << shijian[i] << ", Qhe[" << i << "]: " << qhe[i] << std::endl; } return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值