Click here to Skip to main content
15,888,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include<iostream>
using namespace std;
Class one
{
	public:
	string first;
	string second;
	int previousValue;
	int nextValue;
	void getData();
	void setData();
};
class two
{
	public:
	one array[10];
	void loadRecord();
};
int main()
{
	two ins;
	return 0;
}
two::loadRecord()
{
	for(int i=0;i<10;i++)
	{
		array[i]=//doesnot take input
	}
	for(int i=0;i<10;i++)
	{
		cout<<array[i]<<endl;//doesnot give output
	}

}


What I have tried:

the code above i have tried but it didnt give the output
Posted
Updated 19-Mar-16 11:46am

At this line:
C++
two ins;

..you create an instance "ins" of your class two. And that's all your program does before it terminates.

You need to actually call loadRecord() on it.

And on this line:
C++
array[i]=

..it looks like you want to assign a new instance of your class one to the individual array indices but there already are (uninitialized) instances.

There are more issues but I suggest you start with fixing these.

I would recommend you to use names for your classes, class members and local variables that actually mean something. "one", "two", "ins", "array" will get pretty confusing once your programs get a bit larger.
 
Share this answer
 
v2
Comments
Maciej Los 19-Mar-16 16:14pm    
Hawk eye!
Member 12398690 20-Mar-16 6:23am    
it was mistake when i type the code.
but even-though it will not gives output.
Sascha Lefèvre 20-Mar-16 7:02am    
You attempt to use the operator << with your "whole" class one but there is no operator defined for that. You could either use the operators defined for standard types by sending the members of class one one after another to the output stream or define ("overload") the << operator for your class one.
Sascha Lefèvre 20-Mar-16 7:05am    
Also, you attempt to assign a string to the array indices of array but array is of type one so you would have to assign instances of one to it. Which is unneccessary because it already contains (uninitialized) instances. Instead you might want to set the members of the instances of each array index.
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
 
Share this answer
 
Comments
Member 12398690 20-Mar-16 6:22am    
ok then

#include<iostream>
using namespace std;
Class one
{
public:
string first;
string second;
int previousValue;
int nextValue;
void getData();
void setData();
};
class two
{
public:
one array[10];
void loadRecord();
};
int main()
{
two ins;
ins.loadRecord();
return 0;
}
void two::loadRecord()
{
for(int i=0;i<10;i++)
{
array[i]= "asdfgg";//doesnot take input
}
for(int i=0;i<10;i++)
{
cout<<array[i]<<endl;//doesnot give output
}

}


can you run this code and show me the output.???
Patrice T 20-Mar-16 6:47am    
Use Improve question to update your question with new code.
Run your code on debugger, line by line and see what the code is really doing.
Member 12398690 21-Mar-16 0:54am    
there is no mistake to improve question i just forget to call loadResults() function in main, rest of the code is same. its very simple coding no need debugger to see each line every one can check mate. thanx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900