w0lfyyy Posted May 12, 2015 Report Posted May 12, 2015 am meniu,am programu dar c?nd sunt in meniu si apas 1 pentru programu x sa mi se deschida o alta fereastra ( unde sa aibe si optinunea de back" la meniu) nu sa imi arate sub meniu imediat.."system("cls");" stiam ca e,dar nu pricep...prin/cum ce leg mai exact meniu-program-program-program ? Quote
w0lfyyy Posted May 13, 2015 Author Report Posted May 13, 2015 (edited) #include <iostream>using namespace std;char caesar( char );int main(){int option;do{ cout << "1) Criptarea Cesar " << endl; cout << "2) Underconstruction" << endl; cout << "Please select an option : ";cin >> option;if (option == 1){{ string input; do { cout << "Enter cipertext and press enter to continue." << endl; cout << "Enter blank line to quit." << endl; getline(cin, input); string output = ""; for(int x = 0; x < input.length(); x++) { output += caesar(input[x]); } cout << output << endl; } while (!input.length() == 0);} //end mainchar caesar( char c ){ if( isalpha(c) ) { c = toupper(c); //use upper to keep from having to use two seperate for A..Z a..z c = (((c-65)+13) % 26) + 65; } //if c isn't alpha, just send it back. return c;}return 0;}----alta varianta la limita dar nu inteleg altceva #include<iostream> #include<stdlib.h> #include<iomanip> #include<time.h> #include<stdio.h> using namespace std;int prima(){ system("color 0b"); system("cls"); cout << endl << endl << endl; cout << " Program tema de casa,10+ " << endl; cout << "________________________________________________________________________________" << endl << endl; cout << " Introduceti cifra corespunzatoare optiunii dorite: " << endl << endl; cout << " 2) Cesare" << endl; cout << " 3) Despre program" << endl << endl; cout << " 0) Iesire" << endl << endl << endl; cout << "Optiunea: "; return 1;}int despre(){ system("color 0f"); system("cls"); cout << endl << endl << endl << endl << endl; cout << " > Bine ati venit! < " << endl << endl << endl; cout << "_______________________________________________________________________________" << endl; cout << "9) Meniu anterior 0) Iesire program " << endl << endl; cout << "Optiunea: "; return 1;}int meniu3(){ system("color 0a"); system("cls"); cout << endl; cout << " Cesare " << endl; char caesar(char); { string input; do { cout << "Enter cipertext and press enter to continue." << endl; cout << "Enter blank line to quit." << endl; getline(cin, input); string output = ""; for (int x = 0; x < input.length(); x++) { output += caesar(input[x]); } cout << output << endl; } while (!input.length() == 0); } char caesar(char c) { if (isalpha(c)) { c = toupper(c); //use upper to keep from having to use two seperate for A..Z a..z c = (((c - 65) + 13) % 26) + 65; } return c; }}int iesire(){ system("color 0f"); system("cls"); cout << endl << endl << endl << endl << endl; cout << "_______________________________________________________________________________" << endl; cout << "| ATI ALES SA IESITI DIN PROGRAM |" << endl; cout << "| |" << endl; cout << "| |" << endl; cout << "| VA MULTUMIM |" << endl; cout << "| |" << endl; cout << "| |" << endl; cout << "| |" << endl; cout << "| |" << endl; cout << "|_____________________________________________________________________________|" << endl << endl << endl; cout << " 2015 "; return 1;}int main(int argc, char *argv[]){ int i = 1; if (argc > 1) i = atoi(argv[1]); else prima(); while (i != 0) { if (i == 9) prima(); cin >> i; if (i == 3) meniu3(); if (i == 8) despre(); } if (i == 0) iesire();}cand sterg if (i == 3) meniu3(); si int meniu3() dau run si merge.cand imi bag programu nu mai mergewtf Edited May 13, 2015 by w0lfyyy Quote
S.L.C Posted May 13, 2015 Report Posted May 13, 2015 (edited) Putin complex din cate vad (imi cer scuze daca intr-adevar este). Dar cred ca rezultatul este cea ce cauti.Atentie: Necesita un compiler recent. GCC 4.7+ sau VS 2013+ (posibil sa functioneze si pe un compiler mai vehi dar nu garantez)Testat pe MinGW GCC 4.9.2 x32#include <map>#include <string>#include <cstdlib>#include <iostream>#include <functional>class Menu{protected: typedef std::function<int (Menu &)> Callback; typedef std::map<int, Menu> SubMenus;public: Menu() : m_Id(0), m_Name(""), m_Handler(nullptr) { } Menu(int id, const std::string & name, Callback clbk) : m_Id(id), m_Name(name), m_Handler(clbk) { } Menu & operator [] (int id) { return m_Childrens.at(id); } int Enter() { int result = 0; if (m_Handler) result = m_Handler(*this); return result; } void Insert(const Menu & menu) { m_Childrens[menu.m_Id] = menu; } void Insert(int id, const std::string & name, Callback clbk) { m_Childrens[id] = Menu(id, name, clbk); } void Remove(int id) { m_Childrens.erase(id); } int GetId() const { return m_Id; } const std::string & GetName() const { return m_Name; } const Callback & GetHandler() const { return m_Handler; } bool IsChildren(int id) const { return (m_Childrens.find(id) != m_Childrens.cend()); } Menu & GetChildren(int id) { return m_Childrens.at(id); } const SubMenus & GetChildrens() const { return m_Childrens; }private: int m_Id; std::string m_Name; Callback m_Handler; SubMenus m_Childrens;};void ClearScreen(){ system("cls");}int SharedMenuDisplay(const Menu & menu){ ClearScreen(); std::cout << "Welcome to " << menu.GetName() << std::endl; for (const auto & m : menu.GetChildrens()) { std::cout << "> " << m.second.GetId() << " - " << m.second.GetName() << std::endl; } std::cout << "> 0 - Go Back" << std::endl; std::cout << "Please select a sub menu: "; int choice; std::cin >> choice; return choice;}int Menu_Home(Menu & menu){ int choice; int result = 0; do { ClearScreen(); std::cout << "Welcome to " << menu.GetName() << std::endl; for (const auto & m : menu.GetChildrens()) { std::cout << "> " << m.second.GetId() << " - " << m.second.GetName() << std::endl; } std::cout << "> 0 - To Leave" << std::endl; std::cout << "Please select a sub menu: "; std::cin >> choice; if (choice != 0 && menu.IsChildren(choice)) result = menu.GetChildren(choice).Enter(); } while (choice != 0); return result;}int Menu_A(Menu & menu){ int choice; int result = 0; do { choice = SharedMenuDisplay(menu); if (choice != 0 && menu.IsChildren(choice)) result = menu.GetChildren(choice).Enter(); } while (choice != 0); return result;}int Menu_A_SubMenu_X(Menu & menu){ ClearScreen(); std::cout << "You have selected " << menu.GetName() << std::endl; std::cout << "> Type something and press Enter to go back..." << std::endl; std::string str; std::cin >> str; return 0;}int Menu_A_SubMenu_Y(Menu & menu){ ClearScreen(); std::cout << "You have selected " << menu.GetName() << std::endl; std::cout << "> Type something and press Enter to go back..." << std::endl; std::string str; std::cin >> str; return 0;}int Menu_A_SubMenu_Z(Menu & menu){ ClearScreen(); std::cout << "You have selected " << menu.GetName() << std::endl; std::cout << "> Type something and press Enter to go back..." << std::endl; std::string str; std::cin >> str; return 0;}int Menu_B(Menu & menu){ int choice; int result = 0; do { choice = SharedMenuDisplay(menu); if (choice != 0 && menu.IsChildren(choice)) result = menu.GetChildren(choice).Enter(); } while (choice != 0); return result;}int Menu_B_SubMenu_X(Menu & menu){ ClearScreen(); std::cout << "You have selected " << menu.GetName() << std::endl; std::cout << "> Type something and press Enter to go back..." << std::endl; std::string str; std::cin >> str; return 0;}int Menu_B_SubMenu_Y(Menu & menu){ ClearScreen(); std::cout << "You have selected " << menu.GetName() << std::endl; std::cout << "> Type something and press Enter to go back..." << std::endl; std::string str; std::cin >> str; return 0;}int Menu_B_SubMenu_Z(Menu & menu){ ClearScreen(); std::cout << "You have selected " << menu.GetName() << std::endl; std::cout << "> Type something and press Enter to go back..." << std::endl; std::string str; std::cin >> str; return 0;}int Menu_C(Menu & menu){ ClearScreen(); std::cout << "You have selected " << menu.GetName() << std::endl; std::cout << "> Type something and press Enter to go back..." << std::endl; std::string str; std::cin >> str; return 0;}int main(int argc, char **argv){ Menu home(-1, "Home", &Menu_Home); home.Insert(1, "Menu Item A", &Menu_A); home.Insert(2, "Menu Item B", &Menu_; home.Insert(3, "Menu Item C", &Menu_C); home.GetChildren(1).Insert(1, "Sub Menu Item X", &Menu_A_SubMenu_X); home.GetChildren(1).Insert(2, "Sub Menu Item Y", &Menu_A_SubMenu_Y); home.GetChildren(1).Insert(3, "Sub Menu Item Z", &Menu_A_SubMenu_Z); home[2].Insert(1, "Sub Menu Item X", &Menu_B_SubMenu_X); home[2].Insert(2, "Sub Menu Item Y", &Menu_B_SubMenu_Y); home[2].Insert(3, "Sub Menu Item Z", &Menu_B_SubMenu_Z); return home.Enter();} Edited May 14, 2015 by S.L.C Quote
w0lfyyy Posted May 15, 2015 Author Report Posted May 15, 2015 Este un pic mai complex decat ce vroiam.insa tot nu reusesc sa introduc programu meu intr'un submeniu... Quote