Lab #2
Lab #2
3. Characters (char): Characters are used to store single characters such as 'a', 'b', 'c', etc.
In C++, the char data type is used to define character variables. They are stored as ASCII
values in memory and take 1 byte of memory space. Here's an example:
char grade = 'A';
In this example, the variable "grade" is defined as a char and initialized with the character 'A'.
4. Booleans (bool): Booleans are used to store true or false values. In C++, the bool data
type is used to define Boolean variables. They take 1 byte of memory space. Here's an
example:
bool isMarried = true;
In this example, the variable "isMarried" is defined as a bool and initialized with the value true.
5. Void (void): Void is a special data type that is used to specify that a function does not
return any value. Here's an example:
void printHelloWorld() {
std::cout << "Hello World!" << std::endl;
}
In this example, the function "printHelloWorld" is defined with a void return type, indicating that
it does not return any value. When called, it prints the message "Hello World!" to the console.
Variable: A variable is a named storage location that can hold a value of a particular data type.
Declaring Variable: To declare a variable in C++, you need to specify its data type and give it a
name. Here is the general syntax for declaring a variable:
data_type variable_name;
Here, 'data_type' represents the type of data that the variable will hold, such as int, float, char,
bool, etc. And 'variable_name' is the name given to the variable to uniquely identify it within the
program.
For example, to declare an integer variable called ‘age’, you would use the following code:
int age;
Initializing Variable: After declaring a variable, you can assign a value to it using the
assignment operator (=). For example:
age = 25;
Alternatively, you can declare and initialize a variable in a single line of code, like this:
int age = 25;
This creates a variable called age of type int and initializes it with the value 25.
LAB MANUAL PROGRAMMING FUNDAMENTALS
Note that in C++, variables must be declared before they can be used. This means that you
cannot use a variable in your code until you have declared it.
Example:
Activities:
Activity 1.1: What is meant by the following statement?
“Variables must be declared before they can be used.”
Answer: Please write your answer here.
Activity 1.2: How does the compiler know about the type of the variable?
Answer: Please write your answer here.
Activity 1.3: Can we change the value of variable?
Answer: Please write your answer here.
Activity 1.4: Can we change the value of const at the time of declaration? If yes, then
explain when it cannot be changed.
Answer: Please write your answer here.
Activity 1.5: Declare and initialize all types of variables and show their value on the screen.
Code:
Please write or paste your code snap here.
Output:
Please paste your output screenshot here with your Name and CMS mentioned in it.
Activity 1.6: Differentiate between PascalCase and camelCase, and where should these be
used?
Answer: Please write your answer here.
Activity 1.7: Differentiate between float and double datatypes.
Answer: Please write your answer here.
Activity 1.8: Differentiate between int and unsigned int datatypes.
LAB MANUAL PROGRAMMING FUNDAMENTALS
Rubrics
Absent Student is Student can Student has Student has Student
unable to understand followed constructed perfectly
follow the the provided instructions the implemented
provided laboratory to construct functional/ a working
instructions instructions the working model/
properly. and familiar fundamental schematic/ logic/
The student with the lab schematic/ model/ circuit/
can name environment block block block
the (Trainer/ diagram/ diagram/ diagram/
hardware or software/ code/ model code, and code and
Demonstration simulation IDE), but on the have successfully
platform, cannot protoboard/ successfully executed the
but unable implement trainer/ executed lab objective
to on the simulation the in Realtime
implement platform software. program/ or in a
anything practically run circuit simulation
practically or on the on software environment
or on the software platform and
software produced the
desired
results
Category Ungrade Very Poor Poor Fair Good Excellent
d
Percentage [0] [1-20] [21-40] [41-60] [61-80] [81-100]
Marks 0.0 0.01 - 0.20 0.21 - 0.40 0.41 - 0.60 0.61 - 0.80 0.81 - 1.0
Date Total Instructor’s Signature
Marks