Pages

Thursday, July 11, 2013

Assert function in C++

/*
QUESTION:
Define a class CRecord with two private data members that store a name and an integer item number.

Define a getRecord() function member of the CRecord class that will set values for the data members

by reading input from the keyboard and a putRecord() function member that outputs the values of

the data members. Implement the getRecord() function such that calling program can detect when a

zero item number is entered(use assert function). Test your CRecord class with a main() function that reads and outputs

CRecord objects until a zero item number is entered.
 




CODE:
*/
#include <iostream>
#include<cassert>
using namespace std;
class CRecord{
char name[20];
int item_no;
public:
 void getRecord(){
  cout<<"\n\n\nEnter Name: ";
  cin>>name;
  cout<<"\nEnter item no: ";
        cin>>item_no;
  assert(item_no != 0);
 }
 void putRecord(){
      cout<<"\n\nName is: "<<name ;
   cout<<"\nItem NO is: "<<item_no ;

 }
};


int main(){
 CRecord obj1;
 while(1){
 obj1.getRecord();
 obj1.putRecord();


 }

 return 0;
}

No comments:

Post a Comment