Professional Documents
Culture Documents
1-First Simple Program // Structure - CPP: Main Project File
1-First Simple Program // Structure - CPP: Main Project File
// struct Declaration
struct Student{
// variable fields can be accessed from outside
string Name;
int ID;
string Department;
long PhoneNumber;
}student1,student2;/* we can declar objects here before ;*/
int main(){
// 1 - using struct without functions
cout<<"Enter data for first student:\n";
cout<<"Enter the student name: ";
cin>>student1.Name;
cout<<"Enter the student ID: ";
cin>>student1.ID;
cout<<"Enter the student department: ";
cin>>student1.Department;
cout<<"Enter the student phone Number: ";
cin>>student1.PhoneNumber;
//second student
cout<<"Enter data for second student:\n";
cout<<"Enter the student name: ";
cin>>student2.Name;
cout<<"Enter the student ID: ";
cin>>student2.ID;
cout<<"Enter the student department: ";
cin>>student2.Department;
cout<<"Enter the student phone Number: ";
cin>>student2.PhoneNumber;
cout<<"\n\n\t student Data";
cout<<"\nID\tName\tDepartment\tPhone\n";
cout<<student1.ID<<"\t"<<student1.Name<<"\
t"<<student1.Department<<"\t"<<student1.PhoneNumber<<"\n";
cout<<student2.Name<<"\t"<<student2.ID<<"\
t"<<student2.Department<<"\t"<<student2.PhoneNumber<<"\n";
system("PAUSE");//getch(); on dev
return 0;
}
// struct Declaration
struct Student{
// variable fields can be accessed from outside
string Name;
int ID;
string Department;
long PhoneNumber;
};/* we can declar objects here before ;*/
int main(){
//declaring a student as an array of objects
Student s[2];
cout<<"\n\t enter data for 2 students";
for (int i = 0; i < 2; i++){
cout<<"\n Enter the student name";
cin>>s[i].Name;
cout<<"\n Enter the student ID";
cin>>s[i].ID;
cout<<"\n Enter the student department";
cin>>s[i].Department;
cout<<"\n Enter the student phone Number";
cin>>s[i].PhoneNumber;
}
cout<<"\n\t the student data are \nn";
cout<<"\nID \t Name \t Department \t Phone \n\n";
for (int i = 0; i < 2; i++){
cout<<s[i].ID<<"\t"<<s[i].Name<<"\t"<<s[i].Department<<"\
t"<<s[i].PhoneNumber<<"\n";
}
system("PAUSE");//getch(); on dev
return 0;
}