You are on page 1of 9

National University of Computer and Emerging Sciences

Lab Manual
for
Programming Fundamentals

Department of Computer Science


FAST-NU, Lahore, Pakistan
Instructions:
• Work in this lab individually. Discussion is not allowed.
• Evaluation of tasks will be conducted in the lab.
• Anyone caught indulging in 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.

PROBLEM 1
Task 0:
My First Computer Program 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.
Task 1:

• Write the above code in the file in the editor.


• Compile the code and observe the program output.

➢ Task 2:
Write a C++ program to print “Hello!! Welcome to the world of programming” on the
console.
➢ Task 3:

• Write the above code in the file in the editor


• Compile the code and observe the program output.
Task 4:

• Write the above code in the file in the editor.


• Compile the code and observe the program output.
• Change the above code to print the table 10 and 3

PROBLEM 2
Task1: Write a program that declares and initializes an integer. If the number is positive, print
"The number is positive."

Task2: Write a program that checks if a number is odd or even. The program should take an
integer input from the user and print either "The number is even" or "The number is odd."

Task3: Write a program that assigns a grade (A, B, C, D, or F) based on a student's score. Use
the following criteria:
90 and above: A
80 to 89: B
70 to 79: C
60 to 69: D
Below 60: F

Problem 3
Task 1: You're tasked to write a program that declares and initializes a number. Determine
whether this number lies within the range of 10 to 50 (both inclusive).

Task2: Given an age, determine if the person is a teenager. A teenager is someone whose age
is between 13 and 19 (both inclusive).

Task3: In a particular country, the legal age for voting is 18 and for driving is 21. Check if a
person is eligible for voting, driving, both, or none based on their age.

Task4: On a highway, the safe speed range for driving is between 45 mph and 70 mph. Write a
program that checks whether a car's current speed is safe.

Task5: A store is open if it's a weekday (where days are represented as 1 for Monday to 5 for
Friday) and the time is between 9 AM (inclusive) and 9 PM (exclusive). Determine if the store is
open based on user input for the day and time.

You might also like