Hi im new in need of help!

This is a discussion on Hi im new in need of help! within the C++ Programming forums, part of the General Programming Boards category; Hi everyone! Im new at his forum and I need some help with this assignmnent I have! Just so you ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    7

    Question Hi im new in need of help!

    Hi everyone! Im new at his forum and I need some help with this assignmnent I have! Just so you have an idea, I am NOT a computer science major...and I have no idea of what Im doing so help is appreciated!

    My assignment is the "Diamond" assignment and I already have the code done! but one last thing i have to do... to write a class. To be more specific.. ''
    Write a class called Diamond. Have the appropriate data members for that class. Also have a constructor and a function to output the diamond."

    This is my code in .cpp

    Code:
     
    #pragma once 
    
    class Diamond
    {
    public:
    	Diamond(void);	
    	~Diamond(void);
    };
    
    #include "stdafx.h"
    #include<iostream>
    using namespace std;
    
    int main(){
    int n,i,j; //integer
    char symbol; //character
    cout<<"Enter the character, and length: ";
    cin>>symbol;
    
    cin>>n;
    if(n %2 ==0 || n<0 || n >21) // indicates the number has to be even, greater than 0 and less than 21
    {
         do{
                cout<<"You have entered an illegal value for the length.  It must be between 1 and 21.";
                cin>>n;
                }
    	 while(n %2 ==0 || n<0 || n >21); // the do will run if this condition is followed
     }
     for(i=0;i<n/2;i++) // range for the loop
    	                  // number of rows divided by 2 and increased by 1
     {
      for(j=n/2-i;j>=0;j--)
      cout<<" "; // output blank space
      cout<<symbol; // output character intered
      for(j=1;j<=2*i;j++)
      cout<<" ";
      if(i>0)
      cout<<symbol;
      cout<<endl;
     }
     for(i=n/2;i>=0;i--)
     {
      for(j=n/2-i;j>=0;j--)
      cout<<" ";
      cout<<symbol;
      for(j=1;j<=2*i;j++)
      cout<<" ";
      if(i>0)
      cout<<symbol;
      cout<<endl;
     }
    
    system("pause");
    }
    I suck at classes.... any idea on how to do it?
    Thank you!
    Last edited by C++wannabe; 03-07-2011 at 07:31 PM.

  2. #2
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Mention what problem you ar facing in the above code?

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    thanks for replying! my problem is that I dont know how to write the class. Im pretty sure the code I have there is not enough because I have to assign data members.

    how to I assign them if all I have is int n,i, j, and char symbol.

    I get confused because in a previewous class assignment I had to add the class and have 3 files, one .h, one .cpp and another .cpp (main)

    some GUIDANCE would really help!

    Thank you

  4. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Read this

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    thanks for the link.

    in this case, with the loops, could you please give me an example? and should the constructor be in the .h file and the loops be in the .cpp or everything together?

    thank you for helping i am extremely confused and frustrated

  6. #6
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Place all of the function definitions in header file (.h)...
    All the implementation of header files in .cpp file
    And remaining main from the main.cpp or any_Name.cpp...
    Also read this......
    You must read this...

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    This is what I have so far in the .h file... what am i missing?

    Code:
    #pragma once
    
    #include <iostream>
    using namespace std;
    using std::endl;
    using std::cout; 
    
    class Diamond5
    {
    	int n,i,j;
    	char symbol
    public:
    	Diamond5(void);
    
    	~Diamond5(void);
    };

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    2,756
    This is what I have so far in the .h file... what am i missing?
    Write a class called Diamond. Have the appropriate data members for that class. Also have a constructor and a function to output the diamond
    I don't see a function to output the diamond.

    Jim

  9. #9
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    im sorry to ask this but how you please help me or guide me to create this class?? how to I do it with the loops??? im trying to do it using a template of a previous class assignment but i dont know how to do it

  10. #10
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Quote Originally Posted by C++wannabe View Post
    im sorry to ask this but how you please help me or guide me to create this class?? how to I do it with the loops??? im trying to do it using a template of a previous class assignment but i dont know how to do it
    I shared the links... You must read them carefully...

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,621
    You must not use "using namespace std" in header files.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    ok this is whay i have so far and thank you guys for the help. this is the ONLY error i get

    .h - header file

    Code:
    #pragma once
    
    #include <iostream>
    
    using std::endl;
    using std::cout; 
    
    class Diamond5
    {
    private:  int lengthN;
    		  int lengthI;
    		  int lengthJ;
    	      char symbol;
    public:
    	Diamond5(void);
    	int getLengthN ();
    	int getLengthI ();
    	int getLengthJ ();
    	char getSymbol ();
    	~Diamond5(void);
    public: Diamond5 (int, char);
    public: void printInfo ();
    		void setLengthN (int);
    		void setLengthI (int);
    		void setLengthJ (int);
    		void setSymbol (char);
    }; // end of class definition
    and this is the .ccp (not main)

    Code:
    #include "StdAfx.h"
    #include "Diamond5.h"
    
    Diamond5::Diamond5(int n, int i, int j, char s) // constructor that initializes the values of the data members
    {
    	lengthN = n;
    	lengthI = i;
        lengthJ = j;
    	symbol = s;
    }
    void Diamond5::printInfo(){
    	cout << "Enter the character and lenght: " << symbol << endl;
    	cout << "You have entered an illegal value for the length.  It must be between 1 and 21." << lengthN << endl;
    }
    Diamond5::~Diamond5(void)
    {
    }
    
    Diamond5::Diamond5(void)
    {
    
    }
    void Diamond5::setLengthN (int n)
    {
    	lengthN = n;
    }
    void Diamond5::setLengthI (int i)
    {
    	lengthI = i;
    }
    void Diamond5::setLengthJ (int j)
    {
    	lengthJ = j;
    }
    void Diamond5::setSymbol (char s)
    {
    	symbol = s;
    }
    int Diamond5::getLengthN(){
    	return lengthN;
    }
    int Diamond5::getLengthI(){
    	return lengthI;
    }
    int Diamond5::getLengthJ(){
    	return lengthJ;
    }
    char Diamond5::getSymbol(){
    	return symbol;
    };
    THE ERROR IS : error C2511: 'Diamond5:iamond5(int,int,int,char)' : overloaded member function not found in 'Diamond5'

    THANK U SO MUCH!
    [code]
    Last edited by C++wannabe; 03-08-2011 at 07:35 AM.

  13. #13
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    Sort out your indentation, from a cursory glance it seems you have two different definitions for your constructor.., well you dont have two, you have one, and a call that requires a different definition that does not exist hence the message
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  14. #14
    Registered User
    Join Date
    Mar 2011
    Posts
    7
    I'm sorry if I'm reposting bur I thought I did n is not showing... So here I go again... My problem is the member function n te header definitions.. .
    This is really frustrating but I'm sure it's very simple can somene please show me what changes to make!?!

    Thank u very much

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21