Вы находитесь на странице: 1из 6

Programming Fundamentals -Lab No.1,2 & 3.

Tasks

Task #1 Try to guess what each line of code is doing.

1. int size = 27; Declares and initializes an int variable named


‘size’ and gives it the value 27.
2. cout<< “Hello world.” ;

3. char c=’A’;
cout<<“Character” << c;

4. char i =’a’; int a=i; cout<<a;

5.#include<conio.h>

6. int main() { cout<<”Any Msg”;}

Task # 2 Write a C++ program in which declare some variables with valid
identifiers and conventions rule, to hold your name, your total marks in
previous semester, percentage, your grade, your status of pass or fail etc,
assign them explicitly and print them. Try to declare variables of all data
types and assign the appropriate values.

Task # 3 Write a C++ program to swap two variables.


Task # 4 Write a Program named Address.CPP. An address has

 Student Name
 a house number,
 a street,
 a city,
 a state and a
 postal code.

Supply values at runtime: and print the address with the street on one line
and the city, state, and postal code on the next line.

Task # 5 Write a C++ program to print the ascii value of a given character.
Expected Output
The ASCII value of Z is :90

Task # 6 Write a class that prints out the \n character on the screen.

Task # 7 Consider the variable char character=’A’;


Print the character in single quotes.
Expected output : character in single quotes: ‘A’
Task # 8 Write a program to declare and initialize a
float variable with some value such as 50.25. Then
retrieve the integral part and store it in the variable of
type int, and the fractional part and store it in a variable
of type float. Display actual number, integral part
Fractional part.

Expected output

Number: 50.25
Integer part: 50
Fractional part: 0.25

Task # 9 Write a C++ program to convert hours to


minutes and minutes to seconds
Sample Output:
Input Hours: 10
Minutes: 600
Seconds:
Task # 10 Write a C++ program that declares and initializes an uppercase character
variable of your choice and display the next character in the alphabetical order.

Task # 11 Write a C++ program that takes an uppercase


character from the user and display its equivalent lower case
character.
Expected output

Upper case character ‘D’


Lower case character: ‘d’

Task # 12 Write a c++ program, which takes three int values from the user, and print their addition
and average.
Task # 13: In the following program, explain why the value "6" is printed
twice in a row:
// PrePostDemo.cpp

int main() {
int i = 3;
i++;
cout<<i; // "4"
++i;
cout<<i; // "5"
cout<<++i; // "6"
cout<<i++; // "6"
out<<i; // "7"
}

Task #14 Write a C++ program to print a face. Expected Output


+ " " +
[| o o |]
| ^ |
| '-' |
+-----+

Вам также может понравиться