[go: up one dir, main page]

0% found this document useful (0 votes)
65 views3 pages

C++ Lab 7 Alpha

This lab manual provides tasks to practice nested loops and arrays in C++. The tasks include: 1. Writing a program to calculate average grades of 3 students over 4 exams using nested loops. 2. Printing various patterns using nested loops. 3. Inputting values into an array, and displaying odd and even values. 4. Allowing a user to input a value and check if it exists in an array. 5. Observing code snippets with nested loops and arrays, correcting any errors, and writing the output.

Uploaded by

Attia Batool
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)
65 views3 pages

C++ Lab 7 Alpha

This lab manual provides tasks to practice nested loops and arrays in C++. The tasks include: 1. Writing a program to calculate average grades of 3 students over 4 exams using nested loops. 2. Printing various patterns using nested loops. 3. Inputting values into an array, and displaying odd and even values. 4. Allowing a user to input a value and check if it exists in an array. 5. Observing code snippets with nested loops and arrays, correcting any errors, and writing the output.

Uploaded by

Attia Batool
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/ 3

LAB MANUAL # 7

Course: Computer Programming (CP-107)


Session: 22CP (Alpha)

Nested Loops and Arrays

This lab has been designed to practice programs of nested loops. We will also practice
handling arrays in c++ including array declaration, initialization and accessing array elements.
Clear concept about nested loops and arrays has already been provided in the class along with
examples.
Objectives:
In this lab, you will practice:
• Using nested loops to repeat actions on data of outer loop.
• Using nested loops to print multiple 2 D patterns.
• Array declaration and initialization.
• Inputting and printing array elements using loop.

Lab Tasks: 15/


Question # 1: 2/
Write a program to compute the average grade of each student in a class of 3 students. Each
student has taken four exams during the semester. The final grade is calculated as the average
of these exam grades. The program should display the average grade of the student. Use
nested loops. Outer loop will keep track of students and inner loop will manage exams of each
student.
Question # 2: 3/
Write a C++ program to print following patterns using while or for loop structure and “setw”
manipulator.

12345 * * * * * * * * * *
1234 * * * * * * * * * *
123 * * * * * * * * * *
12 * * * * * * * * * *
1 * * * * * * * * * *
* * * * * * *
* * * * *
* * *
*
LAB MANUAL # 7
Course: Computer Programming (CP-107)
Session: 22CP (Alpha)

Question # 3: 3/
Write a program in C++ to input 20 values into an array. Find out and display odd and even
values entered in the array.
Question # 4: 3/
Write a program in C++ to input data into an array of 10 elements. Then ask the user to enter
a value from the keyboard and find out the location of the entered value in an array. If the
entered number is not found in the array, display the message “Number not found”. Also ask
the user whether he wants to use the program again or not.
Question # 5: 4/
Observe following codes and write their output. If there is any error in the code, then correct
it and write the output.

int main()
{
int a=1,b=1;
while(a<=6)
{
b=1;
while(b<=a)
{
cout<<"*";
b++;
}
cout<<endl;
a++;
}
int main()
{
int var = 'F';
for (int i = 5; i >= 1; i--)
{
for (int j = 0; j < i; j++)
cout<<char (i+var);
cout<<endl;
}
return 0;
}
int main()
{
int f_arr[5];
LAB MANUAL # 7
Course: Computer Programming (CP-107)
Session: 22CP (Alpha)

cout<<"Enter array elements:";


for(int i=0;i<8;i++)
cin>>f_arr[i];
cout<<"Array elements are:";
for(int i=0;i<sizeof(f_arr);i++)
cout<<f_arr[i]<<endl;
return 0;
}
int main()
{
for(int i=0;i<5;i++)
{
for(int j=0;j<4;j++)
cout<<pow(i*j,2)<<" ";
cout<<endl;
}
return 0;
}

*****************

You might also like