Assignment 04
Assignment 04
Task 01
#include <iostream>
using namespace std;
if (isLeapYear(year))
{
daysInMonths[1] = 29;
}
if (month < 1 || month > 12 || day < 1 || day > daysInMonths[month - 1]) {
cout << "Invalid date." << endl;
return;
}
cout << "Day number of the year: " << dayNumber << endl;
}
int main()
{
int month, day, year;
cout << "Enter date (MM-DD-YYYY): ";
cin >> month >> day >> year;
return 0;
}
Task 02
#include <iostream>
using namespace std;
int main() {
int side;
cout << "Enter the side length of the square: ";
cin >> side;
printSquare(side);
return 0;
}
Task 03
#include<iostream>
using namespace std;
system("pause");
return 0;
}
Task 04
#include<iostream>
using namespace std;
int sumofevenodd(int upper_bound)
{
int sumofEven = 0;
int sumofOdd=0;
for (int i = 1;i <= upper_bound;i++)
{
if (i % 2 == 0)
sumofEven += i;
else
sumofOdd += i;
}
cout << "The sum of Even: " << sumofEven;
cout << "The sum of Odd: " << sumofOdd;
int abs_diff = sumofEven - sumofOdd;
cout << "The absolute difference is : ";
if (abs_diff < 0)
{
abs_diff = abs_diff *(-1);
}
return abs_diff;
}
int main()
{
int n;
cout << "Enter the upper bound number: ";
cin >> n;
cout << sumofevenodd(n);
system("pause");
return 0;
}
Task 05
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double num1, num2, num3;
while (true) {
cout << "Enter three numbers (base exponent result): ";
cin >> num1 >> num2 >> num3;
return 0;
}
Task 06
#include <iostream>
using namespace std;
int main() {
cout << "Perfect numbers between 1 and 1000:\n" << endl;
for (int i = 1; i <= 1000; ++i) {
if (isPerfect(i)) {
cout << i << " is a perfect number." << endl;
printDivisors(i);
cout << endl;
}
}
return 0;
}
Task a
#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter an integer: ";
cin >> num;
return 0;
}
Task b
#include <iostream>
using namespace std;
int main() {
int num1, num2;
char choice;
do {
cout << "Enter two integers: ";
cin >> num1 >> num2;
if (num1 == 0) {
cout << "Division by zero is not allowed." << endl;
}
else if (multiple(num1, num2)) {
cout << num2 << " is a multiple of " << num1 << "." << endl;
}
else {
cout << num2 << " is NOT a multiple of " << num1 << "." << endl;
}
return 0;
}
Task c
#include <iostream>
using namespace std;
void findPreceding(char c1, char c2, char c3, char& p1, char& p2, char& p3) {
p1 = (c1 == 'a') ? 'z' : c1 - 1;
p2 = (c2 == 'a') ? 'z' : c2 - 1;
p3 = (c3 == 'a') ? 'z' : c3 - 1;
}
int main() {
char a, b, c;
char pa, pb, pc;
cout << "The preceding letters are: " << pa << " " << pb << " " << pc << endl;
return 0;
}
Task d
#include <iostream>
#include <cctype> // For the tolower function
using namespace std;
int main() {
char a, b, c, d;
Upper_to_lower(a, b, c, d);
cout << "The lowercase letters are: " << a << " " << b << " " << c << " " << d << endl;
return 0;
}