0% found this document useful (0 votes)
41 views6 pages

Lab1 Tasks

The document describes two programming activities. The first activity involves creating structures for students and date of birth, taking input for 5 students, calculating ages from year of birth, and printing the results. The second activity takes marks in 3 subjects for 5 students as input, calculates average marks, and prints the results in a table with name, faculty, and average. Solutions for both activities are provided using C++ structures.

Uploaded by

goraxi6015
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views6 pages

Lab1 Tasks

The document describes two programming activities. The first activity involves creating structures for students and date of birth, taking input for 5 students, calculating ages from year of birth, and printing the results. The second activity takes marks in 3 subjects for 5 students as input, calculates average marks, and prints the results in a table with name, faculty, and average. Solutions for both activities are provided using C++ structures.

Uploaded by

goraxi6015
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

FACULTY OF COMPUTER SCIENCE AND ENGINEERING

CS 112 Lab Marks: 10

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()

student *p=new student[5];


for(int i=0;i<5;i++)
{

cout<<"enter "<<i+1<<" student name"<<endl;


cin>>p[i].name;

cout<<"enter "<<i+1<<" student faculty"<<endl;

cin>>p[i].faculty;

cout<<"enter the year of birth"<<endl;

cin>>p[i].TT.year;

cout<<"age of "<<i+1<<"student will be:"<<endl;

p[i].TT.age=2017-p[i].TT.year;

cout<<p[i].TT.age<<endl;

cout<<"-----------list of students are--------------"<<endl;

cout<<"student name"<<" "<<"faculty"<<" "<<"Age"<<endl;


for(int i=0;i<5;i++)
{

cout<<p[i].name<<" "<<p[i].faculty<<" "<<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>

using namespace std;

struct courses{

string name;

string faculty;

int course1;

int course2;

int course3;
float avg;

void display()

cout<<"the average of the marks in courses are"<<endl;

avg=(course1+course2+course3)/3;

cout<<avg<<endl;

void display1()

cout<<name<<setw(14)<<faculty<<setw(14)<<avg<<endl;

};

int main()

courses *p=new courses[5];

for(int i=0;i<5;i++)

cout<<"enter "<<i+1<<" student name"<<endl;

cin>>p[i].name;

cout<<"enter "<<i+1<<" student faculty"<<endl;


cin>>p[i].faculty;

cout<<"enter the marks of first course"<<endl;

cin>>p[i].course1;

cout<<"enter the marks of second course"<<endl;

cin>>p[i].course2;

cout<<"enter the marks of third course"<<endl;

cin>>p[i].course3;

p[i].display();

cout<<"-----------list of students are--------------"<<endl;

cout<<"student"<<setw(14)<<"faculty"<<setw(14)<<"AVG"<<endl;

for(int i=0;i<5;i++)

p[i].display1();

}
getch();

return 0;

You might also like