0% found this document useful (0 votes)
3 views4 pages

C++ Class Object and Console Example

The document defines two classes, Object and Console, where Object manages properties and provides methods for printing and setting those properties. The Console class interacts with the user, allowing them to execute commands to get or set properties of the Object instance. The code includes error handling for invalid commands and property access, but contains several syntax errors and inconsistencies that need correction.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

C++ Class Object and Console Example

The document defines two classes, Object and Console, where Object manages properties and provides methods for printing and setting those properties. The Console class interacts with the user, allowing them to execute commands to get or set properties of the Object instance. The code includes error handling for invalid commands and property access, but contains several syntax errors and inconsistencies that need correction.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Class Object()

{
 
 
        Public:
        Object()
        {
               Prop1=”Arbitrary 1st property”;
        }
        Virtual void printAll()
        {
               Cout<<prop1<<” “<<prop2<<endl;
               //when you extend object class modify function to print all
//properties
        }
       
        Virtual int print(string propertyToPrint)
        {
               If(propertytoPrint==”prop1”)
               {
                       Cout<<prop1<<endl;
                       Return 1;
              
               }
                else
               If(propertytoPrint==”prop2”)
               {
                       Cout<<prop1<<endl;
                       Return 1;
              
               }
 
               Else
                       Return -1;
        //when you extend object class add cases for all the various
//properties. Return a positive number in these cases
 
 
        }
        Virtual int set(string propertyToSet, string valueToSet)
        {
               If(propertytoSet==”prop1”)
               {
                       Prop1= valueToSet;
                       Return 1;
              
               }
               Else
               If(propertytoSet==”prop2”)
               {
                      
                       valueToSet = atoi(propertyToSet.c_str());
                                              if(valueToset==0)
                                                             return -1;
                                             
                       Prop1= valueToSet;
                       Return 1;
              
               }
 
               Else
                       Return -1;
        //when you extend object class add cases for all the various
//properties. Return a positive number in these cases
 
 
        }
 
 
        Private:
        String prop1;
        Int prop2;
}
Class Console
{

                 

Public:

Console(Object object)

                myObject = object;

Void run()

While(true)

                {

                                cout << "Enter a command \n>";

Cin>>command;

If(command==”GET”)

                Cin>>param1;//should be a propertyname or *

                If(param1==”*”)

                {
                                [Link]();

                }

                Else

                {

                                Int confirm2=[Link](param1);

                                If(confirm==-1)

                                                Cout<<” nonexistent variable”<<endl;

                }

Else

If(command==”SET”)

                Cin<<argument;

                Int equalsInd= argument.find_first_of(‘=’);

                Param1=[Link](0,equalsInd);

                Param2 = [Link](equalsind +1, [Link]-


([Link]+1));

                Int confirm=[Link](param1,param2);

                If(confirm==-1)

                                Cout<<”Invalid conversion or nonexistent


variable”<<endl;

                               

                //Dans=a ind of equalsis 4

}
else

Cout<<”Invalid command”<<endl;

                }

Private:

String command,argument, param1, param2;

                Object myObject;

You might also like