PF LAB 02 (If Statement)
PF LAB 02 (If Statement)
Lab Manual # 2
Programming Fundamentals
(Section BCS-2A1&2A2)
Objective:
The purpose of this lab is to familiarize you with the programming tool. Lo and behold! You will be
working on Microsoft Visual Studio throughout your journey to learn programming in this course. You
will be able to understand how to make a project in visual studio, how the program is executed and what
the sequence of the output is.
After performing this lab, students shall be able to:
Write C++ programs with understanding of sequences, including different conditions.
• In the Visual C++ project types pane, click Win32, and then click Win32 Console
Application.
• Type a name for the project.
• By default, the solution that contains the project has the same name as the project, but you can
type a different name. You can also type a different location for the project.
• Click OK to create the project.
• If Solution Explorer is not displayed, on the View menu, click Solution Explorer.
• Add a new source file to the project, as follows.
o In Solution Explorer, right-click the Source Files folder, point to Add, and then click
New Item.
o In the Visual C++ node, click C++ File (.cpp), type a name for the file, and then click
Add.
The .cpp file appears in the Source Files folder in Solution Explorer, and the file is opened in the Visual
Studio editor.
• In the file in the editor, type a valid C++ program.
Sample:
Question#2 (10 marks)
Create a C++ program that solicits six integer values from the user and determines the percentage of even
and odd numbers among them. Use two variables named as evenCount, and oddCount variables of type
int that tracks the even and odd counts. This program should not utilize loop constructs, else, and else-if
statements.
Ensure the program follows these steps:
• Prompt the user to input six integer values.
• Calculate the percentage of even numbers and odd numbers among the six inputs.
• Display the calculated percentages to the user.
Sample:
Question#3 (5 marks)
Write a C++ program that declare a variable “Roll_num” of int datatype and assign your roll #
(i.e.,1000). Declare a variable “name” of string datatype and assign your name. Declare a variable
“section” of char datatype and assign your PF Lab section. Print your output in specific sequence:
Question#4 (5 marks)
You're tasked to write a:
• C++ program that declares and initializes a number. Determine whether this number lies within the
range of 10 to 50 (both inclusive).
• C++ program that declares and initializes a number. Determine whether this number lies within the
range of 10 to 50 (both exclusive).
Question#5 (5 marks)
Write the code to find the size of following Variables:
• Int
• String
• Char
• Float
• Double
• Long int
• Short int
(Note: This program should not utilize loop constructs, else, and else-if statements.)
Sample:
Question#7 (5 marks)
Write a program that takes an integer representing a month (1 for January, 2 for February, etc.) and prints
the number of days in that month. Assume it's not a leap year.
(Note: This program should not utilize loop constructs, else, and else-if statements.)
Sample: