Advertisement

08.08.2005 at 01:23PM PDT, ID: 21519902
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

product.exe crashes after entering description (no obvious reason)

Asked by piehoe in Windows MFC Programming

Below the code, if someone can figure out why this code continued to work and all of a sudden decided to crash forever...
please if you can rectify the code...

Thanks a mill

Main.cpp

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include "Product.h"

using namespace std;

int main(int argc, char *argv[])
{Product apple;  

  system("PAUSE");      
  return 0;
}


product.h

#ifndef Product_h
#define Product_h
const int max=30;

class Product
{private:
   
    char *_productname; //dynamic allocation (use pointers), prevent NULL or void
    char *_productdescription; //dynamic allocation (use pointers) prevent NULL or void
    int _price;// x>0 (resolved)
    int _uniquenumber;// unique number  x>0  (resolved)
    static int count;  //unsigned would work as well...              
                   
                   
    protected:
       
    public:
       Product();  
       Product(char*,char*,int);
       void setProductname();
       void setProductdescription();
       void setPrice();
       char *getProductname();
       char *getProductdescription();
       int  getPrice();
       void printProduct(char*, char*, int, int);
             
       
        ~Product();
    };
#endif


Product.cpp


#include <iostream>
#include <stdlib.h>
#include <string.h>
#include "Product.h"

using namespace std;

int Product::count=0;

Product::Product()
{setProductname();
setProductdescription();
setPrice();
_uniquenumber=++count;
printProduct(_productname, _productdescription, _price, _uniquenumber);
}

Product::~Product()
{
}

Product::Product(char*,char*,int)
{}

void Product::setProductname()
{char *name=new char [30];
 cout<<"Enter the products name"<<endl;
cin.get(name,30);
char s;
do{
    cin.get(s);
    }while(s!='\n');
strncpy(_productname, name, 30);
delete[]name;
}


void Product::setProductdescription()
{char *description=new char [30];
 cout<<"Enter the products description"<<endl;
cin.get(description,30);
char s;
do{
    cin.get(s);
    }while(s!='\n');
strncpy(_productdescription, description, 30);
delete[]description;
}

void Product::setPrice()
{
    do{cout<<"Enter products price"<<endl;
    cin>>_price;
    }while(_price<=0);    
}

char *Product::getProductname()
{return _productname;}
                     
char *Product::getProductdescription()
{return _productdescription;}

int Product::getPrice()
{return _price;}

void Product::printProduct(char*, char*, int, int)
{cout<<endl<<endl<<"******************"<<endl;
    cout<<"Product: "<<_productname<<endl;
cout<<"Description: "<<_productdescription<<endl;
cout<<"Price: "<<_price<<endl;    
cout<<"Productnumber: "<<_uniquenumber<<endl;
cout<<"******************"<<endl;}


Start Free Trial
 
Keywords: product.exe crashes after entering d…
 
Loading Advertisement...
 
[+][-]08.09.2005 at 01:15AM PDT, ID: 14630623

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Windows MFC Programming
Sign Up Now!
Solution Provided By: venkaiah
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.09.2005 at 01:16AM PDT, ID: 14630626

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44