Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Can someone help me create a gui interface for this?
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cyberguy




PostPosted: Thu Nov 19, 2009 6:25 pm   Post subject: Can someone help me create a gui interface for this?

# include <stdio.h>
# include <string.h>
# include <iostream>
# include <fstream>
#include <stdlib.h>
# include <cstring>

using namespace std;

// Declare Global Variable

struct node {
int Prod_Id ;
char Prod_Name [20];
char Prod_Category [10];
char Prod_Supplier [20];
float Prod_WholeSalePrice ;
float Prod_RetailSalePrice ;
float Prod_CostPrice;
int Prod_stockcount;
int order;
node *next;// Pointer to next node
} product;



node *start_ptr = NULL;
node *temp1, *temp2;
node *current;

int rec_num ;


//###########################################
void addproduct () {

string tempValue;
bool ok;
ofstream PRODUCT ("PRODUCT.txt", ios::app|ios::out);



//data to be added to file
//record number
temp1 = new node;
cout <<"\nAdd Product \n";
rec_num++; //add one to customer count
cout << "\n##### New Product #####";
cout << "\nRecord Number: " << rec_num;
//validation to check field length

ok=false;
do{
cout << "\nEnter Product ID: ";
cin >> tempValue;
temp1->Prod_Id = atoi(tempValue.c_str());
if (temp1->Prod_Id = atoi(tempValue.c_str())){
ok=true;}
else{
ok=false;
cout << "Invalid Numeric Value!";
}
}while(ok!=true);
PRODUCT << temp1->Prod_Id << endl;

//**************
//validation to check field length
ok = false;
do{

cout <<"\nEnter Product Name: ";
cin >> tempValue;
//input
//checks to see if length of first name was exceeded


if(tempValue.length()>20){
ok=false;
cout <<"\nProduct Name Too Long!";
}else{
ok=true;
}
}while(ok!=true);
strcpy(temp1->Prod_Name, tempValue.c_str());
PRODUCT << temp1->Prod_Name << endl;
//**************

//validation to check field length
ok = false;
do{

cout <<"\nEnter Product Category: ";
cin >> tempValue;
//input
//checks to see if length of first name was exceeded


if(tempValue.length()>10){
ok=false;
cout <<"\nProduct Category Name Too Long!";
}else{
ok=true;
}
}while(ok!=true);
strcpy(temp1->Prod_Category, tempValue.c_str());
PRODUCT << temp1->Prod_Category<< endl;
//**************
//validation to check field length
ok = false;
do{

cout <<"\nEnter Supplier Name: ";
cin >> tempValue;



if(tempValue.length()>20){
ok=false;
cout <<"\nProduct Supplier Name is Too Long!";
}else{
ok=true;
}
}while(ok!=true);
strcpy(temp1->Prod_Supplier, tempValue.c_str());
PRODUCT << temp1->Prod_Supplier<< endl;


//**************

//validation for numeric fields
ok=false;
do{
cout << "\nEnter Whole Sale Price: ";
cin >> tempValue;
temp1->Prod_WholeSalePrice = atof(tempValue.c_str());
if (temp1->Prod_WholeSalePrice = atof(tempValue.c_str())){
ok=true;}
else{
ok=false;
cout << "Invalid Numeric Value!";
}
}while(ok!=true);
PRODUCT << temp1->Prod_WholeSalePrice<< endl;
//**************

//validation for numeric fields
ok=false;
do{
cout << "\nEnter Retail Sale Price: ";
cin >> tempValue;
temp1->Prod_RetailSalePrice = atof(tempValue.c_str());
if (temp1->Prod_RetailSalePrice = atof(tempValue.c_str())){
ok=true;}
else{
ok=false;
cout << "Invalid Numeric Value!";
}
}while(ok!=true);
PRODUCT << temp1->Prod_RetailSalePrice<< endl;

//**************

//validation for numeric fields
ok=false;
do{
cout << "\nEnter Number of products in stock: ";
cin >> tempValue;
temp1->Prod_stockcount = atoi(tempValue.c_str());
if (temp1->Prod_stockcount = atoi(tempValue.c_str())){
ok=true;}
else{
ok=false;
cout << "Invalid Numeric Value!";
}
}while(ok!=true);
PRODUCT << temp1->Prod_stockcount<< endl;

//**************
//validation for numeric fields
ok=false;
do{
cout << "\nEnter OutStanding Order: ";
cin >> tempValue;
temp1->order = atoi(tempValue.c_str());
if (temp1->order = atoi(tempValue.c_str())){
ok=true;}
else{
ok=false;
cout << "Invalid Numeric Value!";
}
}while(ok!=true);
PRODUCT << temp1->order<< endl;

//**************
//validation for numeric fields
ok=false;
do{
cout << "\nEnter Cost Price: ";
cin>>tempValue;
temp1->Prod_CostPrice = atof(tempValue.c_str());
if (temp1->Prod_CostPrice = atof(tempValue.c_str())){
ok=true;}
else{
ok=false;
cout << "Invalid Numeric Value!";
}
}while(ok!=true);
PRODUCT << temp1->Prod_CostPrice<< endl;
//**************



temp1->next = NULL;

//set up link to this node
if (start_ptr == NULL)
start_ptr = temp1;
else {
temp2 = start_ptr;
//we know this is not NULL - list not empty!
while (temp2->next != NULL){
temp2 = temp2->next;//move to next link in chain
}
temp2->next = temp1;
}



}//end addPRODUCT

//**************
void findProduct() {

node *current;
int target;
bool found;

cout << "\n**********************Find Product******************** ";
cout << "\nEnter Product Id: ";
cin >> target;
found = false;
current = start_ptr;
if (current == NULL)
cout << "The list is empty!" << endl;
else {
while (current != NULL && found==false) {
if (target == current->Prod_Id){ //display customer
found = true;
cout << "\nProduct ID: " << current->Prod_Id;
cout << "\nProduct Name: " << current->Prod_Name;
cout << "\nProduct Category: " << current->Prod_Category;
cout << "\nProduct's Supplier: " << current->Prod_Supplier;
cout << "\nWhole Sale Price: " << current->Prod_WholeSalePrice;
cout << "\nRetail Price: " << current->Prod_RetailSalePrice;
cout << "\nCost Price: " << current->Prod_CostPrice;
cout << "\nNumber In Stock: " << current->Prod_stockcount;
cout << "\nOutstanding Order: " << current->order;
cout << endl;
}
current = current->next;
}
if (found==false) cout << "\nNo Matching Customer Found!" << endl;
}

}//end of findCustomer

//******************
void viewAll() {


cout << "\n##### View ALL #####";

if (temp1 == NULL)
cout << "The list is empty!" << endl;
else {
temp1 = start_ptr;
while (temp1 != NULL) { // Display details for what temp points to
cout << "\nProduct ID: " << temp1->Prod_Id;
cout << "\nProduct Name: " << temp1->Prod_Name;
cout << "\nProduct Category: " << temp1->Prod_Category;
cout << "\nProduct's Supplier: " << temp1->Prod_Supplier;
cout << "\nWhole Sale Price: " << temp1->Prod_WholeSalePrice;
cout << "\nRetail Price: " << temp1->Prod_RetailSalePrice;
cout << "\nCost Price: " << temp1->Prod_CostPrice;
cout << "\nNumber In Stock: " << temp1->Prod_stockcount;
cout << "\nOutstanding Order: " << temp1->order;
cout << endl;


temp1 = temp1 -> next;

}
cout << "\nEnd of list!" << endl;
}

}//end of viewAll

//############################################
void deleteProduct() {

node *currentP;
node *prevP;

int target;
bool found;

cout << "\n##### Delete Customer #####";
cout << "\nEnter Product ID: ";
cin >> target;

found = false;
prevP = NULL; //there is no previous pointer for the first node
currentP = start_ptr; //point to first item in list

//visit each node, maintaining a pointer to
//the previous node we just visited.
while (currentP != NULL && found==false) { //for (currP = link; currP != NULL; prevP = currP, currP = currP->getNext()) {
if (target == currentP->Prod_Id){
found=true; // if (currP->getData() == item) { /* Found it. */
if (prevP == NULL) { //item is first item in list
start_ptr = currentP->next; //link = currP->getNext();/* Fix beginning pointer. */
} else {
prevP->next = currentP->next;
}
delete currentP; /* Deallocate the node. */
cout << "\nEntry deleted!" << endl;
rec_num--;
}
prevP = currentP;
currentP = currentP->next;
}//end while


if (found==false) cout << "\nNo Matching Customer Found!" << endl;

}//end of deleteProduct

//############################################


//############################################
int main (void){
//Declare local variables

char choice;


do {
cout << "******MAIN MENU******\n";
cout << "Choose One of the Following:\n";
cout << "(1) Add Product\n";
cout << "(2) Find Product\n";
cout << "(3) View All Records\n";
cout << "(4) Delete Product\n";
cout << "(5) Exit\n";

cin >> (choice);
switch (choice) {

case '1':
addproduct ();
break;
case '2':
findProduct ();
break;
case '3':
viewAll();
break;
case '4':
deleteProduct();
break;

case '5':
exit (0);
break;
}//end switch
} while(choice != '5');
return 0;
}//end of main
Sponsor
Sponsor
Sponsor
sponsor
cyberguy




PostPosted: Thu Nov 19, 2009 6:35 pm   Post subject: RE:Can someone help me create a gui interface for this?

Fore example a database gui interface
Tony




PostPosted: Thu Nov 19, 2009 6:50 pm   Post subject: Re: Can someone help me create a gui interface for this?

cyberguy @ Thu Nov 19, 2009 6:25 pm wrote:
# include <stdio.h>
# include <string.h>
#include <stdlib.h>
# include <cstring>
...
char Prod_Name [20];


I thought this was supposed to be a C++ program.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
cyberguy




PostPosted: Thu Nov 19, 2009 7:15 pm   Post subject: RE:Can someone help me create a gui interface for this?

yes it is but i'm trying to manipulate the code to get a gui.....
cyberguy




PostPosted: Thu Nov 19, 2009 7:21 pm   Post subject: RE:Can someone help me create a gui interface for this?

however can you help me get this read from file work

void read (){

ifstream infile ("PRODUCT.txt");
string line ;
temp1 = new node;


if (infile.is_open())
{
cout <<"\nLoading Files.....\n";


while (!infile.eof() && temp1 != NULL )
{
cout << line;
rec_num++;
getline ( infile , line);
temp1->Prod_Id = atoi(line.c_str());
strcpy(temp1->Prod_Name, line.c_str());
strcpy(temp1->Prod_Category, line.c_str());
strcpy(temp1->Prod_Supplier, line.c_str());
temp1->Prod_WholeSalePrice = atof(line.c_str());
temp1->Prod_RetailSalePrice = atof(line.c_str());
temp1->Prod_stockcount = atoi(line.c_str());
temp1->order = atoi(line.c_str());
temp1->Prod_CostPrice = atof(line.c_str());

temp1->next = NULL;


}

infile.close();
}
else cout << "Unable to open file";

}// END of Read
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: