0% found this document useful (0 votes)
26 views7 pages

PF LAB 02 (If Statement)

Uploaded by

ibrahimahsan485
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)
26 views7 pages

PF LAB 02 (If Statement)

Uploaded by

ibrahimahsan485
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/ 7

National University of Computer and Emerging Sciences

Lab Manual # 2
Programming Fundamentals
(Section BCS-2A1&2A2)

Course Instructor Miss. Hira Butt


Lab Instructor(s) Ahmed Khalid
Hooria Najeeb
Section BCS-2A1 & 2A2
Semester Spring 2024

Department of Computer Science,


Fast NUCES,
Lahore
Instructions:
• Work in this lab individually. Discussion is not allowed.
• Evaluation of tasks will be conducted in the lab.
• Anyone caught indulging in the act of plagiarism would be awarded an “F” grade in this lab.

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.

Creating a New Project


It’s time to start! Go ahead and open up Visual Studio from the desktop or start menu.
When you create an app in Visual Studio, you first create a project and a solution. For this example, you’ll
create a Windows console application.
• Create a project by pointing to New on the File menu, and then clicking Project.

• 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.

Question# 1 (10 marks)


Write a C++ program that uses if statement and prompts the user to enter three integer values a, b, and c.
The program should then calculate and output the sum of these values, excluding any duplicates. If any of
the input values are the same as another, they should not be included in the sum. For instance, if the user
inputs 1, 2, and 3, the program should output 6. If the input is 2, 2, and 3, the output should be 3.
(Note: Do the task without using else, and if -else statement).

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:

Your Name: Ahmed Khalid

Your Roll#: 1000

Your Section: BCS-2A

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

Question#6 (10 marks)


Write a program that simulates a simple calculator. It reads two operands (int type) and an operator
(character type). It performs the following arithmetic operations.
• a+b
• a-b
• a*b

(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:

You might also like