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

Assingment 4 Functions

The document outlines the instructions for Programming Fundamentals Assignment #4 at National University of Computer & Emerging Sciences-Faisalabad. It includes specific tasks involving C++ programming, such as calculating the day number of the year, displaying shapes, calculating powers, summing odd and even numbers, and identifying perfect numbers. The assignment must be submitted by May 7, 2025, with strict guidelines against plagiarism and specific coding requirements.

Uploaded by

Marshmellow
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)
7 views3 pages

Assingment 4 Functions

The document outlines the instructions for Programming Fundamentals Assignment #4 at National University of Computer & Emerging Sciences-Faisalabad. It includes specific tasks involving C++ programming, such as calculating the day number of the year, displaying shapes, calculating powers, summing odd and even numbers, and identifying perfect numbers. The assignment must be submitted by May 7, 2025, with strict guidelines against plagiarism and specific coding requirements.

Uploaded by

Marshmellow
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

National University

o f Co mpu ter & E merging Scie nces-Fai salabad

Programming Fundamentals
Assignment # 4

Note: Carefully read the following instructions.

1. Make a word document with the convention “ROLLNO_SECTION_ASSIGNMENT#” and


put all your C++ source code in it.
2. After every question paste a screenshot of your working code below the source code in the
document file.
3. At the end, when you are done with your tasks, make your submission on google Classroom
with a zip file including all C++ files and complete Visual Studio Project.
4. Deadline 7 May 2025 Wednesday. No Submissions will be accepted after deadline and
deadline will not be extended.
5. Plagiarism will not be tolerated, whether it involves another student or any AI source.
6. All Questions should be solved with nested loops and if else or nested if else, arrays, no
other solutions and hard code will not be acceptable

Task-1

Write a Function that prints the day number of the year, given the date in the form month-day-
year. For example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day
number is 359. The program should check for a leap year. A year is a leap year if it is divisible by
4, but not divisible by 100. For example, 1992 and 2008 are divisible by 4, but not by 100. A year
that is divisible by 100 is a leap year if it is also divisible by 400. For example, 1600 and 2000 are
divisible by 400. However, 1800 is not a leap year because 1800 is not divisible by 400.

Task-2
Write a function that displays at the left margin of the screen a solid square of asterisks whose side
is specified in integer parameter side. For example, if side is 4, the function displays the following:

Task-3
Calculate power of a number x using a function “PowerCalc”. Input integer x and the power p
from user. Pass x and p to PowerCalc function. Calculate and display first p powers of x on console
in the PowerCalc function.

1|Pa ge
National University
o f Co mpu ter & E merging Scie nces-Fai salabad

Example:
PowerCalc(5, 4) will give the following output:
5
25
125
625

Task-4
Write a program that takes a upper_bound integer valaue from the user and passes it to a function
named as sumOfNumbers. Sum the odd and even numbers, respectively, from 1 to a given
upper_bound. Also, compute the absolute difference between both of them and return it to the main
function.

Task-5
Write the definition of a function named as karatosDestruction that takes as input the three
numbers. The function returns true if the first number to the power of the second number equals
the third number; otherwise, it returns false. Assume that the three numbers are of type double. If
false is returned, prompt the user to again provide new values otherwise terminate the program.

2|Pa ge
National University
o f Co mpu ter & E merging Scie nces-Fai salabad

Task-6
An integer is said to be a perfect number if the sum of its divisors, including1 (but not the number
itself), is equal to the number. For example, 6 is a perfect number, because 6=1 +2+ 3. Write a
function is Perfect that determines whether parameter number is a perfect number. Use this
function in a program that determines and prints all the perfect numbers between 1and 1000. Print
the divisors of each perfect number to confirm that the number is indeed perfect.

a) Write a function that takes an integer value and returns the number with its digits reversed.
For example, given the number7631, the function should return 1367.

b) Write a function multiple that determines for a pair of integers whether the second is a
multiple of the first. The function should take two integer arguments and return true if the
second is a multiple of the first, false otherwise. Use this function in a program that inputs
a series of pairs of integers. (Hint: Call this function within do-while loop).

c) Write a program that has a function that takes 3 alphabet characters and find their preceding
alphabets. For example if user entered a, m, y it will show b, n, z. Take input in main, pass
values to function and show the output in main.

d) Write a program that has a function “Upper_to_lower”. It will take 4 alphabets as


parameters in uppercase and will change them to lowercase. Display the changed values in
main.

3|Pa ge

You might also like