i wanna ask about the struct !!!

Write a program that define
A- a struct Teacher with the following members:
1. string variable name
2. integer variable age
B- a struct Course with the following members
1. string variable name for the course name
2. integer variable id for the course id
3. an object T of Teacher struct
C- in the main declare an object C and an array of objects CArray of 10 elements of Course struct
D- By using cin, read the course name, course id, teacher name and teacher age and save them in C object
E- Save the object C in the array and read the next record and save it in the array and so on..
F- Pass the array to the function Print that will print the contents of the array
Example: ObjectOrientedDesigne 112 by Dr. Ali 40 years old



this is the question
when i write the cod i found a problem to under stand who i can read the course name, course id, teacher name and teacher age and save them in C object.
and how to Save the object C in the array and read the next record and save it in the array and so on..
this is my code but i cant finish it and the due date is today please help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
#include<string>
using namespace std;
struct Teacher
{
	string name;
	int age;

};
struct Course
{
	string name_course;
	int id;
	Teacher T;


};
int main()
{
	
	Course c;
	Course Array_c[10];
	cout<<endl;
	cout<<"Please enter the course name : ";
    cin>>c.name_course;
	cout<<"Please enter the course id : ";
    cin>>c.id;	
	cout<<"Please enter the teacher name : ";
    cin>>c.T.name;
	cout<<"Please enter the teacher age : ";
    cin>>c.T.age;
	
		
	return 0;


}
how to Save the object C in the array


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main()
{
	
	Course c;
	Course Array_c[10];
	cout<<endl;
	cout<<"Please enter the course name : ";
    cin>>c.name_course;
	cout<<"Please enter the course id : ";
    cin>>c.id;	
	cout<<"Please enter the teacher name : ";
    cin>>c.T.name;
	cout<<"Please enter the teacher age : ";
    cin>>c.T.age;
	
       // Save the struct into the first position in the array
      Array_c[0] = c;
		
	return 0;
}

thinks very very mach .
what about "read the next record and save it in the array and so on.."
i cant understand it .......
thinks again :)
Loops.
Starts about a quarter of the way down.
http://www.cplusplus.com/doc/tutorial/control/
Last edited on
thinks very very mach .
this is the final code but i still have a problem look down

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<iostream>
#include<string>
using namespace std;
struct Teacher
{
	string name;
	int age;

};
struct Course
{
	string name_course;
	int id;
	Teacher T;


};
void print (Course Array_c)
{
	for(int i=0;i<=10;i++)
		cout<<Array_c[i]<<endl; //their is a problem here but i cant know it 


}
int main()
{
	
	Course c;
	Course Array_c[10];
	cout<<endl;
	cout<<"Please enter the course name : ";
    cin>>c.name_course;
	cout<<"Please enter the course id : ";
    cin>>c.id;	
	cout<<"Please enter the teacher name : ";
    cin>>c.T.name;
	cout<<"Please enter the teacher age : ";
    cin>>c.T.age;
	
		Array_c[0]=c;
	for(int i=0;i<10;i++)
	{
		cout<<"Please enter the course name : ";
    cin>>c.name_course;
	cout<<"Please enter the course id : ";
    cin>>c.id;	
	cout<<"Please enter the teacher name : ";
    cin>>c.T.name;
	cout<<"Please enter the teacher age : ";
    cin>>c.T.age;
	Array_c[i]=c;
	

	
	}
	print(Array_c);// and here !!!

	

	return 0;

}
You'll have to output the individual components of each structure

e.g. cout << Array_c[0].name_course;
ok thinks agian but when i pass the array to the function print their is a problem i cant solve look here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
int main()
{
	
	Course c;
	Course Array_c[10];
	cout<<endl;
	cout<<"Please enter the course name : ";
    cin>>c.name_course;
	cout<<"Please enter the course id : ";
    cin>>c.id;	
	cout<<"Please enter the teacher name : ";
    cin>>c.T.name;
	cout<<"Please enter the teacher age : ";
    cin>>c.T.age;
	
		Array_c[0]=c;
	for(int i=0;i<10;i++)
	{
		cout<<"Please enter the course name : ";
    cin>>c.name_course;
	cout<<"Please enter the course id : ";
    cin>>c.id;	
	cout<<"Please enter the teacher name : ";
    cin>>c.T.name;
	cout<<"Please enter the teacher age : ";
    cin>>c.T.age;
	Array_c[i]=c;
	

	
	}
	print(Array_c);//her is the problem 


	return 0;



}
void print (Course Array_c)

what does your function print accept? What kind of parameter? (This is not a trick question - your function accepts one kind of object, and you're trying to pass it something completely different)
Last edited on
thanks vary vary mach your owsame :)
Topic archived. No new replies allowed.