VC++ not allowing cin of all variables in a class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jul
    New Member
    • Jul 2007
    • 15

    VC++ not allowing cin of all variables in a class

    Design and implement a base class Bands in your program. The Bands class contains information of colour codes. From the base class, derived three other classes, one for each of the component described above (Resistor, Inductor, and PTC). Resistor class will contain the number of bands, tolerance, and unit of measurement (Ohms, kilo-Ohms, mega-Ohms). Inductor class will contain the fixed number of bands (4), tolerance, and unit of measurement (only in micro-Henry). PTC class will contain the number of bands, temperature coefficient (only at 0.3% per degree Celsius), types (two types are available), and unit of measurement (only in kilo-Ohms).

    Example of user entries are as follows (user entry in bold, computed result in italic and bold):

    Component type: R
    Number of Bands <3/4>: 4
    Colour bands (separated by spaces): Green Green Red
    Tolerance: Silver
    Value of the RESISTOR is: 5.5 kilo-Ohms, 10% tolerance

    You are required to exercise creativity and object oriented approach in your program design and may add other features; you should also make your program as friendly as possible to the users.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

    Then when you are ready post a new question in this thread.

    MODERATOR

    Comment

    • Jul
      New Member
      • Jul 2007
      • 15

      #3
      Ttz wat i've done, which i've no idea how to continue...
      [code=cpp]
      void Bands::get_valu e()
      {
      cout<<" Component type: "<<endl;
      cin>> type;
      cout<<"Number of Bands <3/4>: "<<endl;
      cin>> num;
      cout<< "Colour 1: "<<endl;
      cin>>c1;
      cout<< "Colour 2: "<<endl;
      cin>>c2;
      cout<< "Colour 3: "<<endl;
      cin>>c3;
      cout<<"Toleranc e: "<<endl;
      cin>> tol;
      }

      void main()
      {
      Bands resistor;
      resistor.get_va lue();
      resistor.show_v alue();
      }[/code]
      Last edited by sicarie; Jul 23 '07, 03:44 PM. Reason: Code tags, full code snipped

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by sicarie
        Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.
        Please read the post and follow the instructions. (ie, where are you stuck, what have you tried, use code tags, ask specific questions - other things that the Guidelines ask you to do...)

        Comment

        • Jul
          New Member
          • Jul 2007
          • 15

          #5
          Need guidance in tis prog. of mine. Bcoz the only Colour 1 can be entered, den the rest juz cout themselves. Wana noe watz wrong wif my prog. Really need help.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by Jul
            Wana noe watz wrong wif my prog.
            Please do write proper English; this is an international Forum and the lingua
            franca happens to be English, not some sms-speak. I was inclined to help you
            but this sillyness kept me from doing so. If you want to be taken seriously you
            should write in a grown-up way.

            kind regards,

            Jos

            Comment

            • Jul
              New Member
              • Jul 2007
              • 15

              #7
              Need guidance in this program of mine. And the only Colour 1 can be entered, then the rest just cout themselves. Want to know what is wrong with my program. Really need help.

              Comment

              • sicarie
                Recognized Expert Specialist
                • Nov 2006
                • 4677

                #8
                Originally posted by JosAH
                Please do write proper English; this is an international Forum and the lingua
                franca happens to be English, not some sms-speak. I was inclined to help you
                but this sillyness kept me from doing so. If you want to be taken seriously you
                should write in a grown-up way.

                kind regards,

                Jos
                Which also happens to be in the Posting Guidelines...

                Comment

                • sicarie
                  Recognized Expert Specialist
                  • Nov 2006
                  • 4677

                  #9
                  Originally posted by Jul
                  Need guidance in this program of mine. And the only Colour 1 can be entered, then the rest just cout themselves. Want to know what is wrong with my program. Really need help.
                  What do you mean "the rest just cout themselves"? Can you post an example of the output and explain what is incorrect about it?

                  Comment

                  • Jul
                    New Member
                    • Jul 2007
                    • 15

                    #10
                    Originally posted by sicarie
                    What do you mean "the rest just cout themselves"? Can you post an example of the output and explain what is incorrect about it?
                    There are 3 colours need to be key in by user. After the user key in, the colour that input by user will be displayed. However, only the 1st colour can be key in by user, the other 3 cannot. And the program continues displaying the prompting of colours till the end of the program.

                    Comment

                    • sicarie
                      Recognized Expert Specialist
                      • Nov 2006
                      • 4677

                      #11
                      My g++ compiler made me change void main to int main (which should be done anyway) and then worked.

                      Output:

                      sicarie@sandbox ~/bin/cpp
                      $ ./a.exe
                      Component type:
                      1
                      Number of Bands <3/4>:
                      1
                      Colour 1:
                      2
                      Colour 2:
                      3
                      Colour 3:
                      4
                      Tolerance:
                      5
                      Value of the 1is3225

                      This is in cygwin with g++

                      Comment

                      • Jul
                        New Member
                        • Jul 2007
                        • 15

                        #12
                        Originally posted by sicarie
                        My g++ compiler made me change void main to int main (which should be done anyway) and then worked.

                        Output:

                        sicarie@sandbox ~/bin/cpp
                        $ ./a.exe
                        Component type:
                        1
                        Number of Bands <3/4>:
                        1
                        Colour 1:
                        2
                        Colour 2:
                        3
                        Colour 3:
                        4
                        Tolerance:
                        5
                        Value of the 1is3225

                        This is in cygwin with g++

                        I don't get it. I'm saying the program is to be run by c++ compiler, not g++ or something else.

                        Comment

                        • sicarie
                          Recognized Expert Specialist
                          • Nov 2006
                          • 4677

                          #13
                          Originally posted by Jul
                          I don't get it. I'm saying the program is to be run by c++ compiler, not g++ or something else.
                          g++ is the GNU C++ compiler. It is a C++ compiler. It is a part of this.


                          Which compiler and version are you running?

                          Comment

                          • Jul
                            New Member
                            • Jul 2007
                            • 15

                            #14
                            Originally posted by sicarie
                            g++ is the GNU C++ compiler. It is a C++ compiler. It is a part of this.


                            Which compiler and version are you running?
                            I'm using MS Visual Studio 2005

                            Comment

                            • sicarie
                              Recognized Expert Specialist
                              • Nov 2006
                              • 4677

                              #15
                              Originally posted by Jul
                              I'm using MS Visual Studio 2005
                              I have no comment as to the adaptability and flexibility of M$ and their products (I'm a Linux person myself). I'm sure there is actually some standard that they decided it would be a good idea to conform to there.

                              Have you tried to create a separate class and include it in your main function?

                              Comment

                              Working...