// 删除商品信息 void Operate::Delete() { int j = -1; char choice; while (true) { cout << "\n\n\t\t\t\t\t 请先浏览商品后再进行删除\n\n\t\t\t\t\t "; system("pause"); // 在删除前,寻找要删除的商品 Browse(); j = Query(); if (j >= 0) { // 删除查找到的商品 char c; cout << "\n您确定要删除该商品的信息吗?(Y / N) [ ]\b\b"; // 清除缓存区 cin.clear(); cin.ignore(); cin >> c; if (c == 'Y' || c == 'y') { // erase 删除该组数据 vec.erase(vec.begin() + j); cout << "\n删除成功,还要继续删除商品信息吗?(Y / N) [ ]\b\b"; // 清除缓存区 cin.clear(); cin.ignore(); cin >> choice;
时间: 2023-05-29 08:03:45 浏览: 76
if (choice == 'N' || choice == 'n') break; } else { cout << "\n\n\t\t\t\t\t 操作已取消,返回主菜单\n\n\t\t\t\t\t "; system("pause"); break; } } else { cout << "\n\n\t\t\t\t\t 您输入的商品编号不存在,请重新输入\n\n\t\t\t\t\t "; } } }
该函数的作用是删除商品信息。首先会提示用户先浏览商品信息,然后会调用Browse()函数展示商品信息,再调用Query()函数查询要删除的商品信息。如果查询到了要删除的商品,会提示用户确认是否要删除该商品信息,如果用户确认删除,则会调用vector的erase函数删除该商品信息。同时,还会提示用户是否继续删除其他商品信息。如果查询到的商品编号不存在,则会提示用户重新输入。如果用户取消操作,则会返回主菜单。
相关问题
美化界面 <!-- 商品信息内容 --> <div class="container" > <div class="left"> <div class="actor"> <img width="30%" :src="$route.query.img | fmtImg" > </div> </div> <div class="right"> <h2> {{ $route.query.name }}</h2> <div class="banner-price"> <p class="params-item"><span class="params-label">价格</span> <span class="price-delete">{{$route.query.price}}</span> </p> <p><span class="params-label">促销价</span> <span class="price-strong">{{$route.query.onlineprice}}</span></p> </div> <div class="banner-params"> <p class="params-item"><span class="params-label">发货地</span>上海</p> <p class="params-item"><span class="params-label">快递方式</span>顺丰包邮</p> </div> <div class="banner-quantity"><input type="number" min="1" class="ipt-quantity"></div> <div class="banner-operate"><span class="btn-operate btn btn-dark"> 立即购买 </span> <span @click="addCart($route.query.id)" class="btn-operate btn btn-dark"> 加入购物车 </span></div> <br> <div class="banner-state"> <p class="params-item"><span class="params-label">服务承诺</span> <span class="params-label deep-gray">正品保证</span> <span class="params-label deep-gray">极速退款</span> <span class="params-label deep-gray">赠运费险</span> <span class="params-label deep-gray">七天无理由退换</span> </p> </div> </div> </div> </div>
这是一个 HTML 代码片段,用于展示商品信息的页面。其中包括商品的图片、名称、价格、促销价、发货地、快递方式、购买数量选择、立即购买和加入购物车等按钮,以及商品的服务承诺。此外,还有一些样式类,如 container、left、right、actor、banner-price、params-item、params-label、price-delete、price-strong、banner-params、banner-quantity、banner-operate 和 banner-state 等,用于美化页面的展示效果。
完成下列的 String 类,并在主函数 main( )中测试它。 class String { public: String(const char *str = NULL); // constructor String(const String &other); // copy constructor ~ String(void); // destructor String & operate =(char *str); String & operate =(const String &other);// 重载=运算符 int operator==(String &other); // 重载==运算符 int operator==(char *str); private: char *m_data; // used for storing the string int length; };
下面是 String 类的实现:
```cpp
#include <cstring>
class String {
public:
String(const char* str = NULL);
String(const String& other);
~String();
String& operator=(const char* str);
String& operator=(const String& other);
int operator==(String& other);
int operator==(const char* str);
private:
char* m_data;
int length;
};
String::String(const char* str) {
if (str == NULL) {
length = 0;
m_data = new char[1];
m_data[0] = '\0';
}
else {
length = strlen(str);
m_data = new char[length + 1];
strcpy(m_data, str);
}
}
String::String(const String& other) {
length = other.length;
m_data = new char[length + 1];
strcpy(m_data, other.m_data);
}
String::~String() {
delete[] m_data;
}
String& String::operator=(const char* str) {
if (m_data == str) {
return *this;
}
delete[] m_data;
if (str == NULL) {
length = 0;
m_data = new char[1];
m_data[0] = '\0';
}
else {
length = strlen(str);
m_data = new char[length + 1];
strcpy(m_data, str);
}
return *this;
}
String& String::operator=(const String& other) {
if (m_data == other.m_data) {
return *this;
}
delete[] m_data;
length = other.length;
m_data = new char[length + 1];
strcpy(m_data, other.m_data);
return *this;
}
int String::operator==(String& other) {
return strcmp(m_data, other.m_data) == 0;
}
int String::operator==(const char* str) {
return strcmp(m_data, str) == 0;
}
```
在主函数中可以这样测试:
```cpp
#include <iostream>
int main() {
String str1("hello");
String str2("world");
String str3(str1);
std::cout << "str1 = " << str1 << std::endl;
std::cout << "str2 = " << str2 << std::endl;
std::cout << "str3 = " << str3 << std::endl;
str2 = str1;
std::cout << "After str2 = str1, str2 = " << str2 << std::endl;
if (str1 == str2) {
std::cout << "str1 is equal to str2" << std::endl;
}
else {
std::cout << "str1 is not equal to str2" << std::endl;
}
if (str1 == "hello") {
std::cout << "str1 is equal to \"hello\"" << std::endl;
}
else {
std::cout << "str1 is not equal to \"hello\"" << std::endl;
}
return 0;
}
```
阅读全文