0% found this document useful (0 votes)
57 views7 pages

Knowledge Unit of Science and Technology: Laboratory Manual (CC1021) : (Programming Fundamentals) (Semester Fall-2021)

This document is a laboratory manual for a programming fundamentals class covering switch statements in C++ and an introduction to loops. It provides examples of switch statements, the different types of loops in C++ including for, while, and do-while loops, and tasks for students to complete involving writing C++ programs that use switch statements and loops. The tasks include programs to check vowels/consonants, print days in a month, grade descriptions, printing natural numbers, square patterns, inputting and printing tables, and printing squares of odd numbers.

Uploaded by

Hassam Shahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views7 pages

Knowledge Unit of Science and Technology: Laboratory Manual (CC1021) : (Programming Fundamentals) (Semester Fall-2021)

This document is a laboratory manual for a programming fundamentals class covering switch statements in C++ and an introduction to loops. It provides examples of switch statements, the different types of loops in C++ including for, while, and do-while loops, and tasks for students to complete involving writing C++ programs that use switch statements and loops. The tasks include programs to check vowels/consonants, print days in a month, grade descriptions, printing natural numbers, square patterns, inputting and printing tables, and printing squares of odd numbers.

Uploaded by

Hassam Shahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

University of Management and Technology

Knowledge Unit of Science and


Technology
Laboratory Manual

[CC1021]: [Programming Fundamentals]


[Semester Fall-2021]
Class: [BSCS, BSIT]
Lab [5]: [Switch statement in C++ and introduction to Loops]

Instructor: [Ms. Hifza Munir]

[CC1021]: [Programming Fundamentals] Page 1


University of Management and Technology

Switch statement in C++


A switch statement allows a variable to be tested for equality against a list of values. Each value
is called a case, and the variable being switched on is checked for each case.

[CC1021]: [Programming Fundamentals] Page 2


University of Management and Technology

[CC1021]: [Programming Fundamentals] Page 3


University of Management and Technology

Loops
In the programming world, the loop is a control structure that is used when we want to execute a
block of code, multiple times. It usually continues to run until and unless some end condition is
fulfilled.

Without Loops:

we have three types of Loops in C++:

 For Loop
 While Loop
 Do While Loop

[CC1021]: [Programming Fundamentals] Page 4


University of Management and Technology

For Loop

For loop is a counter control loop.

Syntax
for ( init; condition; increment )
{
statement(s);
}
Example

[CC1021]: [Programming Fundamentals] Page 5


University of Management and Technology

Lab Task:

1. Write a C++ program to input an alphabet and check whether it is vowel or


consonant using switch case.  
2. Write a C++ program print total number of days in a month using switch case.
3. Write a program in C++ to accept a grade and declare the equivalent description.
Using Switch Statement.

Grade Description

E Excellent

V Very Good

G Good

A Average

F Fail

Test Data :
Input the grade :A
Expected Output :
You have chosen : Average

[CC1021]: [Programming Fundamentals] Page 6


University of Management and Technology
4. Write a program in C++ to display n terms of natural number. 
Sample Output:
Input a number of terms: 7
The natural numbers upto 7th terms are:
1234567
5. Write a program in C++ to print a square pattern with # character. 
Sample Output:
Print a pattern like square with # character:
--------------------------------------------------
Input the number of characters for a side: 4
####
####
####
####
6. Write a C++ program to input a table and print its table.
7. Write a C++ program to print the square of the first 20 odd positive integers

[CC1021]: [Programming Fundamentals] Page 7

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy