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

Assignment no 0-WPS Office

This document is a C++ program that outputs a student's name and ID, extracts the year from the ID, and checks if that year is a leap year. It also prompts the user to enter a month and calculates the number of days in that month, accounting for leap years in February. The program includes error handling for invalid month inputs.

Uploaded by

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

Assignment no 0-WPS Office

This document is a C++ program that outputs a student's name and ID, extracts the year from the ID, and checks if that year is a leap year. It also prompts the user to enter a month and calculates the number of days in that month, accounting for leap years in February. The program includes error handling for invalid month inputs.

Uploaded by

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

Assignment no 01

Cs201

#include <iostream>

#include <string>

using namespace std;

int main() {

// Step 1: Output student's name and ID

string name = "Your Name"; // Replace with your actual name

string studentID = "bc123450000"; // Replace with your actual VUID

cout << "Name: " << name << endl;

cout << "Student ID: " << studentID << endl;

// Step 2: Extract the year from studentID

// Drop the last two digits and take the next four digits

string numericPart = studentID.substr(2, studentID.length() - 2); // Get numeric part

string yearStr = numericPart.substr(numericPart.length() - 4, 4); // Get the year part

int year = stoi(yearStr); // Convert to integer

// Step 3: Check if the year is a leap year

bool isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);

if (isLeapYear) {

cout << year << " is a leap year." << endl;


} else {

cout << year << " is not a leap year." << endl;

// Step 4: Month selection and days calculation

int month;

cout << "Enter the month (1-12): ";

cin >> month;

int days;

switch (month) {

case 1: // January

case 3: // March

case 5: // May

case 7: // July

case 8: // August

case 10: // October

case 12: // December

days = 31;

break;

case 4: // April

case 6: // June

case 9: // September

case 11: // November

days = 30;
break;

case 2: // February

if (isLeapYear) {

days = 29;

} else {

days = 28;

break;

default:

cout << "Invalid month! Please enter a number between 1 and 12." << endl;

return 1; // Exit the program with an error code

// Step 5: Output the number of days in the month

cout << "Number of days in month " << month << ": " << days << endl;

return 0;

You might also like