i need plenty help!!! with some C++

Discussion in 'C++' started by Resh, May 6, 2007.

  1. Resh

    Resh New Member

    Joined:
    May 6, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Hi my name is Resh.....i am seriously desperate for some help in C++ can any body help me. This is due on Thursday 10th May 2007 and this is my last resort because i can't get this out PLEASE PLEASE PLEASE HELP!!

    SECTION A

    In preparation a C++ source file, a programmer has written the assignment statement in long-hand form as shown below:

    a = a + 12;

    rather than in its short-hand form shown here:

    a+=12;

    This also applies to other operations such as -,*,/ and %.

    Develop a class which reads the source file and provides the necessary operations for replacing the assignment statements as listed below:

    a = a + …...; by a+=……;
    a = a - ……; by a-=….….;
    a = a * ……; by a*=….…;
    a = a / …….; by a/=……..;
    a = a%…….; by a%=……;

    In the above example, the variable ‘a’ is chosen for the purpose of illustration and ‘…’ indicates the rest of the expression that is not of interest to us. For example, in a typical program expressions may appear as:

    volt = volt + value*sqrt(root);
    fraction = fraction / total;

    Write the necessary C++ program to carry out the required transformations.

    SECTION B

    Extend the class developed in Section A so that:

    a) If the message “all” is sent to the object, all assignments are converted to their short form as described in Section A.
    b) An assignment of the form t = t + 1
    is reduced to its post fixed form t++
    c) Explore how the polymorphism feature of C++ could be exploited in this class
    Hierarchy
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    You wait until the last few days and look to US to earn YOUR grade? Get real.
     
  3. Resh

    Resh New Member

    Joined:
    May 6, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    That was very mean! I was have been working on it and it is not like i have absolutely nothing... And this was my last resort because it has been giving me more trouble than i realised and i just thought someone might be able to help....
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    You sound like a whining baby looking for his mama and a sugar tit.

    The only effort you've shown here is in writing your post. There is no reason in the world that we should presume that you are other than lazy. Why? Because you're acting like a huge number of lazy people that we've encountered. If you want to present material that shows that you've busted a sweat of your own, rather than spending all your time conducting panty raids and watching TV, then people will generally form another opinion.

    The world does not owe you anything you haven't worked for. Neither do we. At least, I haven't received MY paycheck from you, yet.
     
  5. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    I'm with Resh. You can presume anything in the world about him, but you have no way of knowing whether you approach the truth. And while you certainly don't have any requirement to reply to his question, that doesn't transalate into a right to insult him. Certainly not with such language.
     
  6. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    I don't have to approach the truth. I'm entitled to judge on the basis of experience. I made one judgement on the first post and replied accordingly. I made a further judgement on the second, and replied further. He's certainly welcome to post his homework elsewhere and compare responses.
     
  7. Resh

    Resh New Member

    Joined:
    May 6, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    DaWei,
    Clearly there is no need to be a know it all because you have incorrectly judged me from both messages. Furthermore i don't seek your sympathy and there is no need to behave the way you have.. .Obviuosly your experience has done you no good because you have no idea how to speak the people. I shall not degrade myself to the extent that your have speaking of other people's panty and what not. However for your own knowledge i am not a guy i am a girl so there are no panty raids that is just one of the things that you have assumed wrongfully. Therefore i suggest you get out a bit more and wait a while longer before you decided to judge anyone on your so called EXPERIENCE because obvious you have much to learn.

    ever_thus,
    Thank you very much for your support clearly you are a nice person. But thank you again
     
  8. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    no use in such speech, instead of it, better tell more clearly , what you need

    you dont know principe of shorthand notations or you just wanna know more about them?
     
  9. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    If you're not lazy, don't act like it. I have over 40 years of experience ranging from EE to owner of my own company. The probability of correctness of my judgement is not 1.0, but it's certainly very high.
     
  10. Resh

    Resh New Member

    Joined:
    May 6, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Do accept my apologies aVague...

    NO actually classes are not my strong point so i did some reading and the program i designed is as follows however my problem with it is i am unsure as to whether i am answering the question from section a in this particular program... Because how i understand it is the section a you need a program to perform the arthmetic tasks and it is not until section b does it need to understand the short hand form.... but that is what i think...

    Code:
    #include<iostream.h>
    #include<conio.h>
    // declaration section:
    class Arithmetic
    {
    	private:
    		int a;
    	public:
    		void seta(int a);
    		void displayArithmeticOperations();
    };
    // implementation section:
    void Arithmetic::displayArithmeticOperations()
    {
    	cout<<”Enter initial value of a”<<a<<endl;
    	//print message and value to screen
    	cout<<”The initial value of a you typed is: “<<a<<endl;
    }
    void main()
    {
    	int a= a+12;
    	//print message and value to screen
    	cout<<”After applying a=a+12 new value of a is: “<<a<<endl;
    	int a= a-12;
    	//print message and value to screen
    	cout<<”After applying a=a-12 new value of a is: “<<a<<endl;
    	int a= a*12;
    	//print message and value to screen
    	cout<<”After applying a=a*12 new value of a is: “<<a<<endl;
    	int a= a/12;
    	//print message and value to screen
    	cout<<”After applying a=a/12 new value of a is: “<<a<<endl;
    	int a= a%12;
    	//print message and value to screen
    	cout<<”After applying a=a%12 new value of a is: “<<a<<endl;
    	getch();
    }
     
    Last edited by a moderator: May 9, 2007
  11. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    This line will not input a value for a:
    Code:
    cout<<”Enter initial value of a”<<a<<endl;
    
    You will need something similar to this:
    Code:
    cout << "Enter initial value of a: ";
    cin >> a;
    if (cin.good)
    {
        cout << "The initial value you entered is " << a << endl;
    }
    else
    {
        cout << "You failed to enter an appropriate value" << endl;
    }
    
    You should not use conio.h, as it is non-portable. Instead of using getch, you may merely do somehting like this:
    Code:
    cin.sync ();
    cin.get ();
    
    The .h forms of include files were initially provided for backward compatibility. You should use <iostream>. There are a number of similar files. The 'C' type files have been renamed mainly like this: math.h >> cmath; stdlib.h >> cstdlib; etc. The old versions won't deal appropriately with the std namespace.
     
  12. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Now it looks like the thread is getting over heated and more personal than on topic.

    I would suggest Resh you see the point of the experts that if you provide as much info as possible they will be able to help you better.

    DaWei there is some things that does not happen with people instantly. I also get irritated when I need to edit the posts for the code block and thats natural for anyone new to the forums and I dont complain to them unless they do the same thing.

    I would leave upto you gentleman's to make the things steady. After all its your community.
     
  13. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    As you can see, my last response has no heat. The OP posted work; I pointed out the errors, suggested solutions, and gave the reasons.
     
  14. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    all happy , so it' over : )
     
  15. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    :D
     
  16. Resh

    Resh New Member

    Joined:
    May 6, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    ok thank you DaWei for you help it was helpful i modified the program a lot and it is up and running perfectly now. However i am have another problem with another program i am getting an external error existing


    --------------------Configuration: attempt on task 3(3) - Win32 Debug--------------------
    Linking...
    attempt on task 3(3).obj : error LNK2001: unresolved external symbol "void __cdecl moveto(int,int)" (?moveto@@YAXHH@Z)
    attempt on task 3(3).obj : error LNK2001: unresolved external symbol "void __cdecl lineto(int,int)" (?lineto@@YAXHH@Z)
    attempt on task 3(3).obj : error LNK2001: unresolved external symbol "void __cdecl setcolor(int)" (?setcolor@@YAXH@Z)
    attempt on task 3(3).obj : error LNK2001: unresolved external symbol "void __cdecl closegraph(int)" (?closegraph@@YAXH@Z)
    attempt on task 3(3).obj : error LNK2001: unresolved external symbol "void __cdecl initgraph(int *,int *,char *)" (?initgraph@@YAXPAH0PAD@Z)
    Debug/attempt on task 3(3).exe : fatal error LNK1120: 5 unresolved externals
    Error executing link.exe.

    attempt on task 3(3).exe - 6 error(s), 0 warning(s)


    Nothing i try seems to get rid of it.
    This is not the same program this is another program
     
  17. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    ...
    as I can see here, you 're working with graphics

    and as I can assume, argument of those functions are out of range ...

    2 moments you need to do:
    1) create new topic ( cause its a new programm, and new problem)
    2) view us a code of a programm
     
  18. Resh

    Resh New Member

    Joined:
    May 6, 2007
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    This the code i am working with below:
    When i compile i am getting no errors however when i build i am getting the 6errors i sent before and nothing i try seems to get rid of it.

    Code:
    #include<stdlib.h>
    #include<time.h>
    #include<math.h>
    #include<conio.h>
    //#include<cstdlib.h>
    
    
    #ifndef WINBGI_H
    #define WINBGI_H
    #include <windows.h>        // Provides the mouse message types
    #include <limits.h>         // Provides INT_MAX
    #include <sstream>          // Provides std::ostringstream
    
    // The standard Borland 16 colors
    #define MAXCOLORS       15
    enum colors { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY, DARKGRAY,
                  LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA, YELLOW, WHITE };
     
    // Drawing Functions
    void initgraph( int *graphdriver, int *graphmode, char *pathtodriver );
    void lineto(int x, int y);
     
    // Miscellaneous Functions
    void moveto(int x,int y);
    void setcolor( int color );
     
    // The various graphics drivers
    enum graphics_drivers { DETECT, CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514, HERCMONO,
                            ATT400, VGA, PC3270 };
     
    // Various modes for each graphics driver
    enum graphics_modes { CGAC0, CGAC1, CGAC2, CGAC3, CGAHI, 
                          MCGAC0 = 0, MCGAC1, MCGAC2, MCGAC3, MCGAMED, MCGAHI,
                          EGALO = 0, EGAHI,
                          EGA64LO = 0, EGA64HI,
                          EGAMONOHI = 3,
                          HERCMONOHI = 0,
                          ATT400C0 = 0, ATT400C1, ATT400C2, ATT400C3, ATT400MED, ATT400HI,
                          VGALO = 0, VGAMED, VGAHI,
                          PC3270HI = 0,
                          IBM8514LO = 0, IBM8514HI };
     
    // Constants for closegraph
    #define CURRENT_WINDOW -1
    #define ALL_WINDOWS -2
    #define NO_CURRENT_WINDOW -3
     
     
    // Window Creation / Graphics Manipulation
    void closegraph( int wid=ALL_WINDOWS );
     
    				
    const int X0=320;
    const int Y0=240;
    const double PI=3.14159;
    const int NUME=30;
    const int DENOM=100;
    const int NUMBER=7;
    const double RAD=3.0;
    const double DELTHETA=0.1;
    const int SEGS=60;
    const int REDUX=3;
    const int MIN=1;
     
    class cluster
    {
    public:
                
    	void display(int size,int x,int y);
    };
     
    class tendril
    {
    public:
                void display(int size,double theta,int x,int y);
    };
     
    void cluster::display(int size,int x,int y)
    {
                if(kbhit())
                            exit(0);
                for(int i=0;i<NUMBER;i++)
                {
                            double theta=i*2*PI/NUMBER;
                            moveto(x,y);
                            tendril t;
                            t.display(size,theta,x,y);
                }
    }
    void tendril::display(int size,double theta,int x,int y)
    {
                for(int j=0;j<size;j++)
                {
                            double chng=rand();
                             if ((chng < NUME) ?-1:1)
      						 {
                                double theta=theta+chng*DELTHETA;
                                double x=x+RAD*sin(theta);
                                double y=y+RAD*cos(theta);
                             }
                            if(size<4)setcolor(RED);
                                        else if(size<13)setcolor(GREEN);
                            else if(size<40)setcolor(LIGHTGREEN);
                            else setcolor(YELLOW);
                            lineto(x,y);
                }
                if(size>MIN)
                {
                            cluster c;
                            int newsize=size/REDUX;
                            c.display(newsize,x,y);
                }
    }
    void main()
    {
                int driver,mode;
                driver=VGA;
                mode=VGAHI;
                initgraph(&driver,&mode,"\\bc45\\bgi");
                rand();
     
                int x=X0,y=Y0;
                int size=SEGS;
                cluster c;
                c.display(size,x,y);
                getch();
                closegraph();
    
    #endif // WINBGI_H
    }
     
    Last edited by a moderator: May 10, 2007
  19. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    What compiler and OS are you using? The code seems to indicate that you are trying to use a Borland library that dates back to before Windows was a protected-mode operating system. That's why I mentioned the non-portability of conio.h. It is not a part of the standard C runtime library. Even if your library (whatever it is) is compatible with modern systems (which I highly doubt), you are obviously missing the library file, itself. Header files only provide declarations. This is all the compiler needs. Library files contain the actual code referred to by those headers. They must exist and be found by the linker.

    The missing files are console control commands. All such commands are non-portable. If you absolutely feel you must have them, then you need to get them for whatever particular hardware platform and operating system you have. There are ways to make those for both Windows and *nix platforms, but again, you won't be able to move your code from one kind of machine to another.

    You are obviously using C++, because of the sstream inclusion. Again, you should dump the pre-standard headers. The only .h file you should have is windows.h and any .h files you write for yourself.

    It is not good to use C-style I/O mixed with C++ streams. Unless you know precisely what you're doing, there is no guarantee of synchronization between the two.

    When you post code, put it in code tags. Put [/code] at the bottom of the code, and
    Code:
     at the top.  HTML pages such as these eat whitespace.  The code tags preserve it.
     
  20. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    Code:
    initgraph(&driver,&mode,"\\bc45\\bgi");
    what does it means?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice