Click here to Skip to main content
15,915,741 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CMDiChilWnd Pin
Ed Gadziemski31-May-02 12:31
professionalEd Gadziemski31-May-02 12:31 
Generalformat %4d Pin
pnpfriend31-May-02 5:50
pnpfriend31-May-02 5:50 
GeneralRe: format %4d Pin
lucy31-May-02 8:14
lucy31-May-02 8:14 
GeneralRe: format %4d Pin
pnpfriend31-May-02 9:04
pnpfriend31-May-02 9:04 
GeneralRe: format %4d Pin
lucy31-May-02 9:10
lucy31-May-02 9:10 
GeneralRe: format %4d Pin
achandra00731-May-02 9:40
achandra00731-May-02 9:40 
GeneralRe: format %4d Pin
pnpfriend1-Jun-02 7:48
pnpfriend1-Jun-02 7:48 
QuestionConverting my C++ program into GUI? Pin
Chson31-May-02 5:52
Chson31-May-02 5:52 
I pretty much have no knowledge of MFC's other than the few tutorials I read here. Anyway, would the program below be simple to convert into a GUI? I tried to create a dialog based application to no avail.

------------------------

// Inventory System

/*
LOGIN/PW:
admin/admin
power/power
end/end
*/

#include <iostream>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

vector<string> vitem;
vector<int> vquantity;

void arecord() {
string name;
int quantity = 0;
cout << endl;
cout << "Enter item name: ";
cin >> name;
cout << "Enter quantity: ";
cin >> quantity;
vitem.push_back(name);
vquantity.push_back(quantity);
}

void dblist() {
cout << endl;
cout << "-----------------------------------------------" << endl;
for (int i=0; i < vitem.size(); i++) {
cout << i << " : " << vitem[i] << " " << vquantity[i] << endl;
}
cout << "-----------------------------------------------" << endl;
}

void drecord() {
int rnumber = 0;
cout << endl;
cout << "What record do you wish to delete: ";
cin >> rnumber;
vitem.erase(vitem.begin() + rnumber);
vquantity.erase(vquantity.begin() + rnumber);
}

void erecord() {
int rnumber = 0;
int nquantity = 0;
vector<string>::iterator n = vitem.begin();
vector<int>::iterator a = vquantity.begin();
string nname;
cout << endl;
cout << "Which record do you wish to modify: ";
cin >> rnumber;
cout << "What will be the new item name: ";
cin >> nname;
cout << "What will be the new quantity: ";
cin >> nquantity;
n[rnumber] = nname;
a[rnumber] = nquantity;
}

void srecord() {
string tsearch;
cout << endl;
cout << "What item do you wish to search for: ";
cin >> tsearch;
for (int i = 0; i < vitem.size(); i++) {
if (vitem[i] == tsearch) {
cout << endl;
cout << i << " : " << vitem[i] << " " << vquantity[i] << endl;
}
}
}

void power() {
int option = 0;
while (option != 4) {
cout << endl;
cout << "USER: POWER" << endl;
cout << "1) Add records." << endl;
cout << "2) List records." << endl;
cout << "3) Search records." << endl;
cout << "4) Quit." << endl;
cout << endl;
cout << "Enter 1, 2, 3, or 4: ";
cin >> option;
if (option == 1)
arecord();
else if (option == 2)
dblist();
else if (option ==3)
srecord();
}
}

void end() {
int option = 0;
while (option != 3) {
cout << endl;
cout << "USER: END" << endl;
cout << "1) List records." << endl;
cout << "2) Search records." << endl;
cout << "3) Quit." << endl;
cout << endl;
cout << "Enter 1, 2, or 3: ";
cin >> option;
if (option == 1)
dblist();
else if (option == 2)
srecord();
}
}

void admin() {
int option = 0;
while (option != 6) {
cout << endl;
cout << "USER: ADMIN" << endl;
cout << "1) Add records." << endl;
cout << "2) List records." << endl;
cout << "3) Delete records." << endl;
cout << "4) Edit records." << endl;
cout << "5) Search records." << endl;
cout << "6) Quit." << endl;
cout << endl;
cout << "Enter 1, 2, 3, 4, 5, or 6: ";
cin >> option;
if (option == 1)
arecord();
else if (option == 2)
dblist();
else if (option ==3)
drecord();
else if (option == 4)
erecord();
else if (option == 5)
srecord();
}
}

int loginpw() {
string login;
string pw;
cout << endl;
cout << "Enter Login: ";
cin >> login;
cout << "Enter Password: ";
cin >> pw;
if (login == "power") {
if (pw == "power")
power();
else
cout << "Wrong password!" << endl;
return -1;
}
else if (login == "end") {
if (pw == "end")
end();
else
cout << "Wrong password!" << endl;
return -1;
}
else if (login == "admin") {
if (pw == "admin")
admin();
else
cout << "Wrong password!" << endl;
return -1;
}
else {
cout << "Invalid login!" << endl;
return -1;
}
}

int load() {
string litem;
int lquantity;
ifstream fin("is.txt");
if (!fin)
return 0;
while (false == fin.eof()) {
fin >> litem >> lquantity;
vitem.push_back(litem);
vquantity.push_back(lquantity);
}
vitem.pop_back();
fin.close();
}

void save() {
ofstream fout("is.txt");
for (int i = 0; i < vitem.size(); i++)
fout << vitem[i] << " " << vquantity[i] << endl;
fout.close();
}

int main() {
load();
loginpw();
save();
return 0;
}
AnswerRe: Converting my C++ program into GUI? Pin
l a u r e n31-May-02 7:45
l a u r e n31-May-02 7:45 
GeneralRe: Converting my C++ program into GUI? Pin
Chson31-May-02 8:51
Chson31-May-02 8:51 
AnswerRe: Converting my C++ program into GUI? Pin
Paul M Watt31-May-02 7:48
mentorPaul M Watt31-May-02 7:48 
GeneralRe: Converting my C++ program into GUI? Pin
Chson31-May-02 8:50
Chson31-May-02 8:50 
GeneralRe: Converting my C++ program into GUI? Pin
Ravi Bhavnani31-May-02 8:57
professionalRavi Bhavnani31-May-02 8:57 
GeneralRe: Converting my C++ program into GUI? Pin
Chson31-May-02 9:58
Chson31-May-02 9:58 
GeneralRe: Converting my C++ program into GUI? Pin
Alexandru Savescu31-May-02 12:47
Alexandru Savescu31-May-02 12:47 
GeneralCTreeCtrl question Pin
Stew31-May-02 4:54
Stew31-May-02 4:54 
GeneralRe: CTreeCtrl question Pin
Tomasz Sowinski31-May-02 5:12
Tomasz Sowinski31-May-02 5:12 
GeneralQuickie: CListCtrl message Pin
31-May-02 4:45
suss31-May-02 4:45 
GeneralRe: Quickie: CListCtrl message Pin
Tomasz Sowinski31-May-02 5:14
Tomasz Sowinski31-May-02 5:14 
GeneralRe: Quickie: CListCtrl message Pin
31-May-02 5:37
suss31-May-02 5:37 
GeneralRe: Quickie: CListCtrl message Pin
Michael Dunn31-May-02 11:48
sitebuilderMichael Dunn31-May-02 11:48 
GeneralMS Installer 2.0 needs .NET framework?!?! Pin
paulccc31-May-02 3:50
paulccc31-May-02 3:50 
GeneralRe: MS Installer 2.0 needs .NET framework?!?! Pin
Nish Nishant31-May-02 4:21
sitebuilderNish Nishant31-May-02 4:21 
GeneralRe: MS Installer 2.0 needs .NET framework?!?! Pin
paulccc31-May-02 4:24
paulccc31-May-02 4:24 
GeneralRe: MS Installer 2.0 needs .NET framework?!?! Pin
Nish Nishant31-May-02 4:38
sitebuilderNish Nishant31-May-02 4:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.