You are on page 1of 6

12214719 JAHONGIR ZIYAEV HOMEWORK#8 LAB#10

Exercise#1

#include <stdio.h>

// Define the Date structure


struct Date {
int year;
int month;
int day;
};

int main() {
// Declare a variable of type Date
struct Date dob;

// Prompt the user to enter their date of birth


printf("Enter your date of birth:\n");

// Input the year


printf("- Year: ");
scanf("%d", &dob.year);

// Input the month


printf("- Month: ");
scanf("%d", &dob.month);

// Input the day


printf("- Day: ");
scanf("%d", &dob.day);

// Output the formatted date of birth


printf("Your DoB: ");

// Output the month based on the entered month number


switch (dob.month) {
case 1:
printf("January");
break;
case 2:
printf("February");
break;
case 3:
printf("March");
break;
case 4:
printf("April");
break;
case 5:
printf("May");
break;
case 6:
printf("June");
break;
case 7:
printf("July");
break;
case 8:
printf("August");
break;
case 9:
printf("September");
break;
case 10:
printf("October");
break;
case 11:
printf("November");
break;
case 12:
printf("December");
break;
default:
printf("Invalid month");
return 1; // Exit the program with an error code
}

// Output the day and year


printf(" %d, %d\n", dob.day, dob.year);

return 0; // Exit the program successfully


}
Exercise#2
#include <iostream>
using namespace std;

// Define the Date structure


struct Date {
int year;
int month;
int day;
};

// Define the Student structure


struct Student {
int id; // student ID number
Date dob; // date of birth
Date graduation; // expected graduation date
};

// Function to get student information from the user


Student getStudentInfo() {
Student newStudent;

cout << "Enter student information:\n";

// Input student ID
cout << "- Student ID: ";
cin >> newStudent.id;

// Input date of birth


cout << "- Date of Birth (Y M D): ";
cin >> newStudent.dob.year >> newStudent.dob.month >> newStudent.dob.day;

// Input expected graduation date


cout << "- Expected Graduation Date (Y M D): ";
cin >> newStudent.graduation.year >> newStudent.graduation.month >>
newStudent.graduation.day;

return newStudent;
}

// Function to display student information


void displayStudentInfo(Student s) {
cout << "\nStudent Information:\n";
cout << "Student ID: " << s.id << endl;
cout << "Date of Birth: " << s.dob.year << "-" << s.dob.month << "-" << s.dob.day << endl;
cout << "Expected Graduation Date: " << s.graduation.year << "-" << s.graduation.month <<
"-" << s.graduation.day << endl;
}

int main() {
// Initialize student information
Student s1 = {123, {2000, 1, 1}, {2026, 2, 28}};

cout << "Init Student Info... ==> " << endl;


displayStudentInfo(s1);

cout << "\nInput the new student information: " << endl;
s1 = getStudentInfo();

cout << "\nReceived Student Info... ==> " << endl;


displayStudentInfo(s1);

return 0;
}
Exercise#3
#include <iostream>
#include <cmath>
using namespace std;

// Define the Point structure


struct Point {
double x;
double y;
};

// Define the Circle structure


struct Circle {
Point center; // center position of the circle
double radius; // radius of the circle
};

// Function to check if a point is inside or on the boundary of a circle


bool isInside(Circle c, Point p) {
// Calculate the distance between the center of the circle and the given point
double distance = sqrt(pow(p.x - c.center.x, 2) + pow(p.y - c.center.y, 2));

// Check if the distance is less than or equal to the radius


return distance <= c.radius;
}

int main() {
// Define points
Point p1 = {0, 0}, p2 = {9.5, 9.5};

// Define a circle
Circle c1 = {{2.5, 2.5}, 4.5};

// Check if points are inside or on the boundary of the circle


if (isInside(c1, p1)) {
cout << "Point p1 is located inside or on the boundary of the circle." << endl;
} else {
cout << "Point p1 is outside the circle." << endl;
}

if (isInside(c1, p2)) {
cout << "Point p2 is located inside or on the boundary of the circle." << endl;
} else {
cout << "Point p2 is outside the circle." << endl;
}

return 0;
}

You might also like