why am i not getting the desired output??

This is a discussion on why am i not getting the desired output?? within the C++ Programming forums, part of the General Programming Boards category; i should be getting firstname, middlename and surname all together as output.... but im getting only the middlename and surname... ...

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    6

    why am i not getting the desired output??

    i should be getting firstname, middlename and surname all together as output.... but im getting only the middlename and surname... where am i wrong???

    Code:
    #include<iostream>
    #include<conio.h>
    #include<string.h>
    using namespace std;
    class name
    {
    	public:
    		string first;
    		string m;
    		string l;
    		string name1;
    		
    		name()
    		{
    			cout<<"enter first name :";
    			cin>>first;
    			}
    			name(string mno,string abc)
    			{
    				m=mno;
    				l=abc;
    				}
    				name(name &z)
    				{
    					name1=z.m+z.l;	
    					
    					}
    					void show()
    					{
    						string fullname=first+name1;
    						cout<<"\nfull name :"<<fullname;
    						}
    };
    main()
    {	
    	string mid;
    	string sur;
    	name n;
    	cout<<"enter middle name :";
    	cin>>mid;
    	cout<<"\nenter surname :";
    	cin>>sur;
    	name n1(mid,sur);
    	name n2(n1);
    	n2.show();
    	getch();
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,804
    Where are you entering a first name for n2?

    What is the purpose of your variables n and n1?

    I really think you need to review your documentation for how C++ classes are used.


    Jim

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,777
    This code will not compile. Please provide your real code when posting. If this code really compiles, then you have a bad compiler and might want to switch (good candidates are Visual C++, gcc and clang++).
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why is my program not replicating the desired output?
    By newbie2012 in forum C Programming
    Replies: 2
    Last Post: 11-16-2012, 03:22 PM
  2. Why is my program not replicating the desired output?
    By newbie2012 in forum C Programming
    Replies: 5
    Last Post: 11-16-2012, 10:53 AM
  3. Not Getting Desired Output
    By DevoAjit in forum C Programming
    Replies: 2
    Last Post: 03-09-2012, 04:46 AM
  4. Replies: 3
    Last Post: 01-08-2004, 08:43 PM
  5. not getting the desired output. WHY???
    By KristTlove in forum C++ Programming
    Replies: 4
    Last Post: 11-06-2003, 01:08 PM

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