“模板:返回上一级”的版本间的差异

来自个人维基
跳转至: 导航搜索
返回上一级
 
(未显示1个用户的7个中间版本)
第1行: 第1行:
<noinclude>
+
<source lang="c">
{{Documentation}}
+
#include <iostream>
</noinclude>
+
#include <string>
 +
#include <vector>
 +
#include <iomanip>
  
<noinclude>
+
using namespace std;
{{Documentation}}
+
</noinclude>
+
  
== 返回上一级 ==
+
class MenuItem {
 +
public:
 +
    string name;
 +
    string link;
 +
    MenuItem(string name, string link) : name(name), link(link) {}
 +
};
  
<div style="text-align: center; margin-top: 10px;">
+
class NavigationBar {
  <a href="{{{1|}}}" style="display: inline-block; background-color: #4CAF50; color: white; padding: 10px 20px; border-radius: 12px; text-decoration: none; font-weight: bold; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); transition: background-color 0.3s;">
+
private:
     {{{2|返回上一级}}}
+
    vector<MenuItem> menuItems;
  </a>
+
 
</div>
+
public:
 +
    // 添加菜单项
 +
    void addItem(const string& name, const string& link) {
 +
        menuItems.push_back(MenuItem(name, link));
 +
    }
 +
 
 +
    // 显示导航栏
 +
    void display() {
 +
        cout << "+----------------------------------------------------+" << endl;
 +
        cout << "|                    导航栏                        |" << endl;
 +
        cout << "+----------------------------------------------------+" << endl;
 +
 
 +
        for (size_t i = 0; i < menuItems.size(); ++i) {
 +
            // 设置每个菜单项的显示格式
 +
            cout << "| " << setw(20) << left << menuItems[i].name
 +
                << " | " << setw(25) << left << menuItems[i].link << " |" << endl;
 +
        }
 +
 
 +
        cout << "+----------------------------------------------------+" << endl;
 +
    }
 +
};
 +
 
 +
int main() {
 +
    NavigationBar navbar;
 +
   
 +
    // 添加菜单项
 +
    navbar.addItem("首页", "http://example.com");
 +
    navbar.addItem("项目概览", "http://example.com/project");
 +
    navbar.addItem("文档指南", "http://example.com/docs");
 +
    navbar.addItem("联系方式", "http://example.com/contact");
 +
 
 +
    // 显示导航栏
 +
    navbar.display();
 +
 
 +
     return 0;
 +
}
 +
 
 +
</source>

2024年12月1日 (日) 00:05的最后版本

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
 
class MenuItem {
public:
    string name;
    string link;
    MenuItem(string name, string link) : name(name), link(link) {}
};
 
class NavigationBar {
private:
    vector<MenuItem> menuItems;
 
public:
    // 添加菜单项
    void addItem(const string& name, const string& link) {
        menuItems.push_back(MenuItem(name, link));
    }
 
    // 显示导航栏
    void display() {
        cout << "+----------------------------------------------------+" << endl;
        cout << "|                    导航栏                        |" << endl;
        cout << "+----------------------------------------------------+" << endl;
 
        for (size_t i = 0; i < menuItems.size(); ++i) {
            // 设置每个菜单项的显示格式
            cout << "| " << setw(20) << left << menuItems[i].name 
                 << " | " << setw(25) << left << menuItems[i].link << " |" << endl;
        }
 
        cout << "+----------------------------------------------------+" << endl;
    }
};
 
int main() {
    NavigationBar navbar;
 
    // 添加菜单项
    navbar.addItem("首页", "http://example.com");
    navbar.addItem("项目概览", "http://example.com/project");
    navbar.addItem("文档指南", "http://example.com/docs");
    navbar.addItem("联系方式", "http://example.com/contact");
 
    // 显示导航栏
    navbar.display();
 
    return 0;
}