0% found this document useful (0 votes)
87 views

PF Assignment

The document contains 14 programming tasks focused on fundamental C++ concepts like variable declaration and initialization, input/output, operators, classes, and more. The tasks involve writing short programs to demonstrate concepts like declaring variables of different data types, swapping variables, printing ASCII values, converting between units, and displaying formatted text like an emoticon face. Students are asked to provide the code, output, and file names for each program.

Uploaded by

Furqan Ahmed
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)
87 views

PF Assignment

The document contains 14 programming tasks focused on fundamental C++ concepts like variable declaration and initialization, input/output, operators, classes, and more. The tasks involve writing short programs to demonstrate concepts like declaring variables of different data types, swapping variables, printing ASCII values, converting between units, and displaying formatted text like an emoticon face. Students are asked to provide the code, output, and file names for each program.

Uploaded by

Furqan Ahmed
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/ 18

1

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

Roll Number:19SW08
Date:07/11/2019
2

Task # 1
Try to guess what each line of code 1. Declares and initializes an int
is doing. variable named ‘size’ and gives it
1. int size = 27; the value 27.

2. cout<< “Hello world.” ; 2. Prints out the String


“Hello World” on the console
window.
Output:Hello World

3. char c=’A’; 3. First it declares and initializes a


cout<<“Character” << c; char variable named ‘c’ and
assigns it “A” and prints out the
following output on screen.
Output: CharacterA

4. char i =’a’; int a=i; cout<<a; 4. First it declares and initializes a


char variable named ‘i’ and
assigns it “a” and then declares an
int variable named ‘a’ and gives it
the value of char i which is its
ASCII value and Finally it prints
out in the ASCII value of char “a”
through int variable a.

5.#include<conio.h> 5. Links the header file Conio.h to


the program to include some
important functions.

6. int main() { cout<<”Any Msg”;} 6. It states that an int value is to be


returned to the system upon
executing and prints the following
output.
Output: Any Msg
Returns 0 value to Os by Default.
3

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.

Program Code:
4

Program Output:

Source and Executable File:

Task#2.cpp

Task#2.exe
5

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

Program Code:
6

Program Output:

Source and Executable File:

Task#3.cpp

Task#3.exe
7

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.

Program Code:
8

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

Program Code:
9

Program Output:

Source and Executable File:

Task#5.cpp

Task#5.exe
10

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

Program Code:
11

Program Output:

Source and Executable File:

Task#6.cpp

Task#6.exe
12

Task # 7

Consider the variable char character = ’A’;


Print the character in single quotes.
Expected output : character in single quotes: ‘A’

Program Code:
13

Program Output:

Source and Executable File:

Task#7.cpp

Task#7.exe
14

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

Program Code:
15

Program Output:

Source and Executable File:

Task#8.cpp

Task#8.exe
16

Task # 9
Write a C++ program to convert hours to minutes and
minutes to seconds
Sample Output:
Input Hours: 10
Minutes: 600
Seconds: 3600

Program Code:
17

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"
18

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


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

You might also like