Lab1 Tasks
Lab1 Tasks
Lab No: 01
Activity01:
Write a program that creates two structures i-e student and DOB(date
of birth) . DOB will be the sub structure of the structure “student”
having variables age, year defined. The student structure will have the
variables : name, faculty defined. Take the data of five students from
the user, Calculate the age of the students from the year of birth input
from the user. Print all the data i-e name, faculty, age in the form of the
table.
Sol:
#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
struct dob{
int year;
int age;
};
struct student{
string name;
string faculty;
dob TT;
};
int main()
cin>>p[i].faculty;
cin>>p[i].TT.year;
p[i].TT.age=2017-p[i].TT.year;
cout<<p[i].TT.age<<endl;
getch();
return 0;
Activity02:
Write a program that takes the marks of five students in three subjects
from the user and print their name, all subjects marks and average
marks in the form of the table. Structure should have the variables :
name, course1, course2 , course3 , average and display function for
displaying the result.
Sol:
#include<iostream>
#include<string>
#include<conio.h>
#include<iomanip>
struct courses{
string name;
string faculty;
int course1;
int course2;
int course3;
float avg;
void display()
avg=(course1+course2+course3)/3;
cout<<avg<<endl;
void display1()
cout<<name<<setw(14)<<faculty<<setw(14)<<avg<<endl;
};
int main()
for(int i=0;i<5;i++)
cin>>p[i].name;
cin>>p[i].course1;
cin>>p[i].course2;
cin>>p[i].course3;
p[i].display();
cout<<"student"<<setw(14)<<"faculty"<<setw(14)<<"AVG"<<endl;
for(int i=0;i<5;i++)
p[i].display1();
}
getch();
return 0;