Using Namespace Struct Int Int Int Int
Using Namespace Struct Int Int Int Int
#include<iostream>
using namespace std;
struct time {
int hours;
int minutes;
int seconds;
};
int main() {
time t;
cout << "enter no. of hours :" << endl;
cin >> t.hours;
cout << "enter no. of minutes :" << endl;
cin >> t.minutes;
cout << "enter no. of seconds :" << endl;
cin >> t.seconds;
t.seconds = t.seconds + (t.minutes * 60) + (t.hours * 3600);
cout << t.seconds << endl;
Task 2:
#include<iostream>
using namespace std;
struct employee {
int hours;
char name[50];
int age;
int salary = 2500;
};
int main() {
employee t;
cout << "enter name :" << endl;
cin.getline(t.name, 50);
cout << "enter no. of working hours :" << endl;
cin >> t.hours;
cout << "enter age :" << endl;
cin >> t.age;
cout << "name:" << t.name << endl;
cout << "age:" << t.age << endl;
cout << "working hours:" << t.hours << endl;
cout << "salary:" << t.salary << endl;
Task 3:
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
struct date {
int datee;
int month;
int year;
};
struct time {
int hours;
int minutes;
int seconds;
};
struct Address
{
int HouseNo;
char c[25];
char City[25];
char Pincode[25];
};
struct event {
struct date a;
struct time b;
struct Address c;
};
int main() {
ofstream MyFile("filename.txt");
event e;
cout << "enter date:" << endl;
cin >> e.a.datee;
cout << "enter month:" << endl;
cin >> e.a.month;
cout << "enter year:" << endl;
cin >> e.a.year;
MyFile << "date of the event:" << e.a.datee << "-" << e.a.month << "-" <<
e.a.year<<"\n";
cout << "enter hours:" << endl;
cin >> e.b.hours;
cout << "enter minutes:" << endl;
cin >> e.b.minutes;
cout << "enter seconds:" << endl;
cin >> e.b.seconds;
MyFile << "time of the event:" << e.b.hours << ":" << e.b.minutes << ":" <<
e.b.seconds<<"\n";
cout << "enter house number" << endl;
cin >> e.c.HouseNo;
cin.getline(e.c.c, 25);
cout << "enter city name:" << endl;
cin. getline(e.c.City,25);
cout << "enter pin code:" << endl;
cin.getline(e.c.Pincode, 25);
MyFile << "address of the event:" << e.c.HouseNo << "," << e.c.City << "," <<
e.c.Pincode << "\n";
}
Task 4:
#include<iostream>
#include<fstream>
using namespace std;
struct student {
char Name[25];
int house;
int street;
char c[25];
char city[25];
char provice[25];
int age;
float gpa;
};
int main() {
ofstream MyFile("dbs.txt");
char ch;
cout << "enter your department \n 1)bba\n2)cs" << endl;
cin >> ch;
student stu;
cin.getline(stu.c, 25);
cout << "enter sudent name" << endl;
cin.getline (stu.Name,25);
cout << "enter house number" << endl;
cin >> stu.house;
cout << "enter street number" << endl;
cin >> stu.street;
cin.getline(stu.c, 25);
cout << "city name" << endl;
cin.getline( stu.city,25);
cout << "enter provive name" << endl;
cin. getline(stu.provice,25);
cout << "enter age " << endl;
cin >> stu.age;
cout << "enter your gpa" << endl;
cin.getline(stu.c, 25);
cin >> stu.gpa;
MyFile << "BBA Student \n" << "Name:" << stu.Name << "\n" << "house
number:" << stu.house << "\n" << "street number:" << stu.street << "\n" << "city
name:" << stu.city << "\n" << "province name:" << stu.provice << "\n"
<< "age:" << stu.age << "\n" << "gpa:" << stu.gpa;
if (ch == '2') {
MyFile << "CS Student \n" << "Name:" << stu.Name << "\n" << "house
number:" << stu.house << "\n" << "street number:" << stu.street << "\n" << "city
name:" << stu.city << "\n" << "province name:" << stu.provice << "\n"
<< "age:" << stu.age << "\n" << "gpa:" << stu.gpa;
}