| 1. |
Write a C++ program to declare and accept an array of professors. Display the details of the department= “COMP.SCI” and the name of the professors start with ‘A’. The structure “college” should contain the following members.prof id as integername and Department as character array |
|
Answer» #include<iostream> using namespace std; struct professor { int id; char name[20]; char dept[20]; } void accept(Professor 7 p);// Function declaration { cout<<"\n "Enter id of Professor:"; cin>>p.id; cout<<"\n "Enter name of the Professor:"; cin>>p.name; cout<<"\n "Enter name of the department:"; cin>>p.dept; } Void display(Professor p) { cout<<"\n professor id"; cin>>p.id; cout<<"\n professor Name:"; cout<<p.name; cout<<"\n Department:"; cout<<p.dept<<end1; } int main() { Professor p[5]; int total = 0; for(int i = 0;i<5;i++) { cout<<"\n professor"<<i+1<<"\n; accept P[i]; } cout<<"\n Name of the professor starting with A \n"; for(int i = 0;i<5;i++) { if(P[i].name[0] = ='A'&& P[i].dept = =''CS") { cout<<"\n professor"<<i+1<<"\n"; display(P[i]); } cin.get(); din.get(); return 0; } Output Professor 1 Enter id of professor: 100 Enter name of the professor: John Enter name of the department: CS Professor 2 Enter id of professor: 101 Enter name of the professor: Janardhan Enter name of the department: ECE Professor 3 Enter id of professor: 102 Enter name of the professor: Albert Enter name of the department: CS Professor 4 Enter id of professor: 103 Enter name of the professor: Asha Enter name of the department: CS Professor 5 Enter id of professor: 104 Enter name of the professor: Han Enter name of the department: EEE Name of the professor starting with A Professor 1 Enter id of professor: 102 Enter name of the professor: Albert Enter name of the department: CS Professor 2. Enter id of professor: 103 Enter name of the professor: Asha Enter name of the department: CS |
|