Lab 03-Programming Fundamentals
Lab 03-Programming Fundamentals
Introduction
Welcome to your favorite programming Lab. In this lab manual, we shall work together to learn
and implement new programming concepts
Skills to be learned:
● Identifying the Variables and Datatypes for any given problem.
● Write a complete program that converts input into the required output.
Introduction
Variables are the containers that are used to store different values. Recall the constraints of
having valid variable names from the class.
● The names can not have spaces
● The names can not start with Numbers
● The names can not have any special Characters
Datatypes are the labels that are associated with each container that are used to store different
values.
The following table lists the data types that are used to store different values.
Datatype Description
Examples:
Valid Example Invalid Examples Description
Skill: Identifying the Variables and Datatypes for any given problem.
Programming Fundamentals
Week 03 - Lab Manual
Following are a few examples of how to declare, initialize, and assign values for different
types of variables.
Skill: Identifying the Variables and Datatypes for any given problem.
Programming Fundamentals
Week 03 - Lab Manual
Skill: Identifying the Variables and Datatypes for any given problem.
Programming Fundamentals
Week 03 - Lab Manual
Skill: Write a complete program that converts input into the required output
In class, you have studied variable declaration that is used to declare a variable of fixed size in
memory. Additionally, the assignment operator is used to assign a value to the declared variable.
Look at the attached example for recalling
these concepts.
Variable declaration
Variable Initialization
Tasks
● Declare a string-type variable and assign it your name and print it on the screen.
● Declare an integer type variable and assign it your roll number and print it on the console
screen
● Initialize a float type variable with your aggregate value and print it on the console
screen.
● Initialize a character type variable with your section and print it on the screen.
● Now, write a program where you take all these values and print them on the screen like
below.
Task01(WP): Write a program that takes a number from the user(console screen) in dollars
and converts it into rupees. 1 Dollar = 200 rupees
Let’s code this one out.
Skill: Write a complete program that converts input into the required output
Programming Fundamentals
Week 03 - Lab Manual
Can you point out 🔎 the problem for the above code?
Yes, in this program, the input value is not entered by the user rather it is set by the
programmer just like the dollar value.
We need the user to enter the value of dollars that he wants to convert into rupees.
We have just the right command for this.
Syntax:
cin >> variablename;
We have slightly modified the code and made the above-mentioned changes and now it is
working according to our requirements.
Great Work Students! You have added another skill to your skillset
Conclusion
Variable Variables are the containers that are used to store different values
Data Type Datatype defines the label according to the type of data that is stored in
the variables.
Skill: Write a complete program that converts input into the required output
Programming Fundamentals
Week 03 - Lab Manual
Task 01(CL): Write a C++ program that inputs from the user his name, roll number,
aggregate, and section and prints it on screen.
Task 02(OP): Write a C++ program that converts the weights from lbs (Pounds) to kgs
(Kilograms). 1lb = 0.45 Kgs
Note: The user enters weights in lbs and the program prints it in kgs.
Task 03(OP): Write a C++ program that takes the length and width of the rectangle from the
user and prints its area. Area = length * width
Task 04(CP): Write a C++ program that takes charge (Q) and time (t) as input from the user
and prints the current (I) on the console. Current(I) = Charge (Q)/Time(t)
Skill: Write a complete program that converts input into the required output
Programming Fundamentals
Week 03 - Lab Manual
Task 05(CP): Write a C++ program that takes the name, matric (out of 1100), intermediate(out
of 550), and Ecat (out of 400) marks of the student and print their aggregate score for UET.
Ecat = 50% & intermediate = 40% & Matric = 10%
Task 06(OP): Write a C++ program that takes the megabytes from the user and converts them
into bits and prints the value on the screen. 1MB = 1024 Kb & 1KB = 1024 Bytes & 1Bytes =
8 Bits
Task 07(OP): You are developing a C++ program for a time-tracking application. The
program needs to take an integer input representing hours and convert it to seconds to
accurately record the time in seconds.
Task 08(OP): You are developing a C++ program for an electrical engineering application.
The program needs to calculate power (in watts) given voltage (in volts) and current (in
amperes) as input.
Skill: Write a complete program that converts input into the required output
Programming Fundamentals
Week 03 - Lab Manual
Task 09(OP): You are building a C++ program for a health and wellness application. To
calculate certain health-related statistics, you need to take a user's age in years as input and
convert it into their age in days.
Notes
Task 10(OP): You are developing a C++ program to keep track of a cricket team's
performance in the Asia Cup tournament. The program needs to take the number of wins,
draws, and losses as input and calculate the number of points the cricket team has obtained so
far, based on the following rules:
Task 11(OP): Scientists have discovered that in four decades, the world will EXPLODE! It
will also take three decades to make a spaceship to travel to a new planet that can hold the
Skill: Write a complete program that converts input into the required output
Programming Fundamentals
Week 03 - Lab Manual
You must calculate the number of people there will be in three decades from now.
Make a variable population and take input from the user that is the world population now.
Assume that every month, someone gives birth to n more people. Also take n from the user as
input. Calculate the number of people there will be when the spaceship is created.
Skill: Write a complete program that converts input into the required output