0% found this document useful (0 votes)
5 views3 pages

Hw04 Solution

The document contains a C++ program that defines a structure for courses and allows the user to input course details such as code, name, class, and attendance. It then creates a second course with modified values based on the first course's data. Additionally, it defines a date structure and initializes it with a specific date, displaying the date information to the user.

Uploaded by

maher sawsak
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)
5 views3 pages

Hw04 Solution

The document contains a C++ program that defines a structure for courses and allows the user to input course details such as code, name, class, and attendance. It then creates a second course with modified values based on the first course's data. Additionally, it defines a date structure and initializes it with a specific date, displaying the date information to the user.

Uploaded by

maher sawsak
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/ 3

//Name :Maher Sawsak

//Student Number : 220208721

#include <iostream>
#include <cstring>
using namespace std;

// Lab 25
struct course {
int courseCode;
char courseName[30];
int courseClass;
int courseAttendance;
};

int main() {
// Lab 25 and 26
course course1, course2;

cout << "Enter course code: ";


cin >> course1.courseCode;

cout << "Enter course name: ";


cin.ignore(); // To handle leftover newline
cin.getline(course1.courseName, 30);

cout << "Enter course class: ";


cin >> course1.courseClass;

cout << "Enter course attendance: ";


cin >> course1.courseAttendance;

cout << "\n--- Course 1 Info ---" << endl;


cout << "Course Code: " << course1.courseCode << endl;
cout << "Course Name: " << course1.courseName << endl;
cout << "Course Class: " << course1.courseClass << endl;
cout << "Course Attendance: " << course1.courseAttendance << endl;

course2.courseCode = course1.courseCode * 2;
course2.courseClass = course1.courseClass * 2;
course2.courseAttendance = course1.courseAttendance * 2;
strcpy(course2.courseName, course1.courseName); // Assign courseName

cout << "\n--- Course 2 Info ---" << endl;


cout << "Course Code: " << course2.courseCode << endl;
cout << "Course Name: " << course2.courseName << endl;
cout << "Course Class: " << course2.courseClass << endl;
cout << "Course Attendance: " << course2.courseAttendance << endl;

// Lab 27: typedef struct date


typedef struct {
int day;
int month;
int year;
char weekday[30];
} date;

date today = {10, 4, 2025, "Thursday"};

cout << "\n--- Today's Date Info ---" << endl;


cout << "Day: " << today.day << endl;
cout << "Month: " << today.month << endl;
cout << "Year: " << today.year << endl;
cout << "Weekday: " << today.weekday << endl;

return 0;
}

You might also like