adplus-dvertising
Perfect 24 U
No Result
View All Result
  • Home
  • KPK NOTES
    • KPK TextBook Board
      • Grade 1
      • Grade 2
      • Grade 3
      • Grade 4
      • Grade 5
      • Grade 6
      • Grade 7
      • Grade 8
      • Grade 9
      • Grade 10 KPTBB BOOK
      • Grade 12 books for KPK
      • Grade 11 BOOK KPK Board
    • Class 7
      • Urdu
    • Class 9
      • Mathematics
      • English Class 9 Notes for KPK
      • 9th Urdu Notes
      • Biology 9th
      • Islamiat 9
      • Computer Science 9th
      • Pak Studies 9
      • Physics 9th
      • Chemistry 9th
    • Class 10
      • English 10th Notes
      • Biology 10 Class
      • CHEMISTRY 10 NOTES
      • class 10 Maths
      • Pak Study 10th
      • Physics 10
      • Urdu 10
    • Class 11 KPK Notes
      • 11 class biology notes KPK
      • 1st Year Mathematics Notes
      • chemistry class 11 notes
      • English FA Fsc Part 1 KPK
      • Islamiat Class 11 for kpk
      • Physics class 11 notes
    • 2nd Years
      • 2nd Year Chemistry Notes
      • Mathematics-XII
      • 2nd year computer science notes
      • 2nd Year Economics Notes
      • 2nd year English notes
      • 2nd year Pakistan Study Notes
      • 2nd Year Physics Notes
      • Bio Fsc Part 2
    • BISE Swat
      • Result
      • Model Papers
      • Chemistry Class 10 Notes
      • Class 11 Computer Science
      • Economics Notes Class 11
      • Statistics Class 11
      • Class 12 Statistics Notes
    • Syllabus
    • Mardan Board
      • 9th Notes
  • AIOU
    • B.ED books
    • B.S AIOU Books
    • Bachelor AIOU Books
    • CT AIOU Books
    • FA
  • BISE Lahore
    • Class X
      • English Class 10th Notes
    • Class IX
      • English Class 9th Notes
    • Class XI
      • English Class 11th Notes
    • Class XII
      • English Class 12th Notes
  • Sindh Board
    • Sindh Textbook Jamshoro
    • Class IX
      • Pak Studies Sindh 9
      • Computer Science 9 Sindh
      • Mathematic Sindh Class 9
      • Chemistry Notes
      • Biology 9
      • Physics
      • Sindh Board English 9th Notes
      • Islamiat Class 9 Sindh
    • Class X
      • Sindh Class 10 Physics
      • Sindh Class 10th English Notes
      • Islamiat Class 10 Sindh
    • Class XI
      • Islamiat
      • English notes class 11 Sindh board
    • Class XII
      • English Notes Sindh board 12th
  • CBSE
    • CBSE Class 9
    • CBSE Class 10
    • CBSE Class 11
    • CBSE Class 12
  • Rawalpindi Board
    • Class 9th
      • English 9th Notes
      • Biology G9
    • Class 10th
      • English 10th Notes
    • Class 11th
      • English 11th Notes
  • FBISE
    • 9 Class
      • Computer Science
      • Biology Notes
      • 9th FBISE Maths
      • Fbise 9 Notes Eng
    • 10 Class
      • English FBISE Notes
    • 11 Class
      • FBISE English 11th
    • 12 Class
      • Class 12 English Notes Fbise
    • FBISE Past Papers
      • 10 Class
      • 9th Past Papers
  • Articles
    • Essay
    • A-Z Universities in Pakistan
    • Admissions
    • All Country Independence Day
    • Countries Info
    • FILMORA
    • Education Qoutes
    • Happy Teacher Day
    • Insurance
    • Islamic
    • Muslim Boys names
    • Nelson’s Mandela
    • PHILONTHROPIC PRACTICES
    • Speeches
    • Story
  • DIT
  • DAE
  • MCQs
  • Technology
    • Marketing Think with Google
    • Science
  • Punjab board
    • Class 11 Notes PTBB
      • Computer Science PTBB Class 11
      • English 11 Notes Punjab
      • Chemsitry PTBB 11th
      • Math Notes PTBB 11th
      • Physics PTBB 11th
      • Urdu PTBB 11th
      • Biology 11th PTBB
    • Class 9
    • Punjab Class 10th
    • Punjab Board Class 10 Chemistry
  • Home
  • KPK NOTES
    • KPK TextBook Board
      • Grade 1
      • Grade 2
      • Grade 3
      • Grade 4
      • Grade 5
      • Grade 6
      • Grade 7
      • Grade 8
      • Grade 9
      • Grade 10 KPTBB BOOK
      • Grade 12 books for KPK
      • Grade 11 BOOK KPK Board
    • Class 7
      • Urdu
    • Class 9
      • Mathematics
      • English Class 9 Notes for KPK
      • 9th Urdu Notes
      • Biology 9th
      • Islamiat 9
      • Computer Science 9th
      • Pak Studies 9
      • Physics 9th
      • Chemistry 9th
    • Class 10
      • English 10th Notes
      • Biology 10 Class
      • CHEMISTRY 10 NOTES
      • class 10 Maths
      • Pak Study 10th
      • Physics 10
      • Urdu 10
    • Class 11 KPK Notes
      • 11 class biology notes KPK
      • 1st Year Mathematics Notes
      • chemistry class 11 notes
      • English FA Fsc Part 1 KPK
      • Islamiat Class 11 for kpk
      • Physics class 11 notes
    • 2nd Years
      • 2nd Year Chemistry Notes
      • Mathematics-XII
      • 2nd year computer science notes
      • 2nd Year Economics Notes
      • 2nd year English notes
      • 2nd year Pakistan Study Notes
      • 2nd Year Physics Notes
      • Bio Fsc Part 2
    • BISE Swat
      • Result
      • Model Papers
      • Chemistry Class 10 Notes
      • Class 11 Computer Science
      • Economics Notes Class 11
      • Statistics Class 11
      • Class 12 Statistics Notes
    • Syllabus
    • Mardan Board
      • 9th Notes
  • AIOU
    • B.ED books
    • B.S AIOU Books
    • Bachelor AIOU Books
    • CT AIOU Books
    • FA
  • BISE Lahore
    • Class X
      • English Class 10th Notes
    • Class IX
      • English Class 9th Notes
    • Class XI
      • English Class 11th Notes
    • Class XII
      • English Class 12th Notes
  • Sindh Board
    • Sindh Textbook Jamshoro
    • Class IX
      • Pak Studies Sindh 9
      • Computer Science 9 Sindh
      • Mathematic Sindh Class 9
      • Chemistry Notes
      • Biology 9
      • Physics
      • Sindh Board English 9th Notes
      • Islamiat Class 9 Sindh
    • Class X
      • Sindh Class 10 Physics
      • Sindh Class 10th English Notes
      • Islamiat Class 10 Sindh
    • Class XI
      • Islamiat
      • English notes class 11 Sindh board
    • Class XII
      • English Notes Sindh board 12th
  • CBSE
    • CBSE Class 9
    • CBSE Class 10
    • CBSE Class 11
    • CBSE Class 12
  • Rawalpindi Board
    • Class 9th
      • English 9th Notes
      • Biology G9
    • Class 10th
      • English 10th Notes
    • Class 11th
      • English 11th Notes
  • FBISE
    • 9 Class
      • Computer Science
      • Biology Notes
      • 9th FBISE Maths
      • Fbise 9 Notes Eng
    • 10 Class
      • English FBISE Notes
    • 11 Class
      • FBISE English 11th
    • 12 Class
      • Class 12 English Notes Fbise
    • FBISE Past Papers
      • 10 Class
      • 9th Past Papers
  • Articles
    • Essay
    • A-Z Universities in Pakistan
    • Admissions
    • All Country Independence Day
    • Countries Info
    • FILMORA
    • Education Qoutes
    • Happy Teacher Day
    • Insurance
    • Islamic
    • Muslim Boys names
    • Nelson’s Mandela
    • PHILONTHROPIC PRACTICES
    • Speeches
    • Story
  • DIT
  • DAE
  • MCQs
  • Technology
    • Marketing Think with Google
    • Science
  • Punjab board
    • Class 11 Notes PTBB
      • Computer Science PTBB Class 11
      • English 11 Notes Punjab
      • Chemsitry PTBB 11th
      • Math Notes PTBB 11th
      • Physics PTBB 11th
      • Urdu PTBB 11th
      • Biology 11th PTBB
    • Class 9
    • Punjab Class 10th
    • Punjab Board Class 10 Chemistry
Perfect 24 U
No Result
View All Result
Home KPK NOTES 2nd Years 2nd year computer science notes

2nd year Computer science Notes Chapter 4 Control Structures

ADVERTISEMENT

2nd year Computer science Notes Chapter 4 Control Structures for kpk board.

KPK Grade 12 Computer Science Notes

Table of Contents

  • KPK Grade 12 Computer Science Notes
  • 2nd year Computer science Notes Chapter 4 Control Structures
  • Q.4) Write a C++ program that takes two integers and characters representing one of the following mathematical operations: +,-,/, or *. Use a switch statement to perform the appropriate mathematical operation on the integers, and display the result. If an invalid operator enters then “Error” message should be displayed and the program should exit (use the exit()  function). 
  • Q.5) Write a program using for loop that prints even numbers from 0 to 20.
  • Q.6) Write a program using while loop that takes an integer for a variable nValue, and returns the sum of all the numbers from 1 to nValue.Hint: For example, nValue=5 should return 15, which is 1+2+3+4+5
  • Q.7) What is wrong with the following for loop?// Print all numbers from 9 to 0for (unsigned int nCount = 9; nCount >=0; nCount –)cout <<nCount <<” “;
  • Q.8) Write a C++ program to read the address of a person and exit when the user enters dot (.) from the keyboard.
  • Q.9) Write a C++ program to find out the area of a triangle and if any side is zero then display the message “There is no triangle”.
  • Q.10) Write a C++ program to input a character from the keyboard and display the message after testing whether it is Vowel or Consonant.
  • What are the 3 types of control structures?

2nd year Computer science Notes Chapter 4 Control Structures

Q.4) Write a C++ program that takes two integers and characters representing one of the following mathematical operations: +,-,/, or *. Use a switch statement to perform the appropriate mathematical operation on the integers, and display the result. If an invalid operator enters then “Error” message should be displayed and the program should exit (use the exit()  function). 

Answer:
int main()
{
int num1, num2, result;
result = 0;
cout << “Enter First Integer : “;
cin >> num1;
cout << “Enter Second Integer : “;
cin >> num2;
cout << “Choose an from the following \n A-For Addtion \n S-For Subtraction \n D-For Division \n M-For Multiplication\n”;
char opeartion;
cout << “Enter a Character (A, S, D, M): “;
cin >> opeartion;
int i = 0;
switch (opeartion)
{
case ‘A’:
result = num1 + num2;
cout << “You Selected Addition \nThe Result is = ” << result << “\n\n” << endl;
break;
case ‘S’:
result = num1 – num2;
cout << “You Selected Subtraction \nThe Result is = ” << result << “\n\n” << endl;
break;
case ‘D’:
result = num1 / num2;
cout << “You Selected Division \nThe Result is = ” << result << “\n\n” << endl;
break;
case ‘M’:
result = num1 * num2;
cout << “You Selected Multiplication \nThe Result is = ” << result << “\n\n” << endl;
break;
default:
cout << “Error! operator is not correct”;
exit(0);
}
return 0;
}
Output:
The output of the program is as follows:

computer science
2nd year Computer science Notes Chapter 4 Control Structures 8

Q.5) Write a program using for loop that prints even numbers from 0 to 20.

Answer:
PROGRAM USING FOR LOOP THAT PRINTS EVEN NUMBERS FROM 0 T0 20:
#include <iostream>
using namespace std;
int main ()
{
int x;
for(x=0 ;x<=20; x=x+1)
if (x%2 ==0)
cout <<“This is an even number”<< x<< “.\n”;
}
Output:
The output of the program is as follows:

2nd year Computer science Notes Chapter 4 Control Structures
2nd year Computer science Notes Chapter 4 Control Structures 9

Q.6) Write a program using while loop that takes an integer for a variable nValue, and returns the sum of all the numbers from 1 to nValue.
Hint: For example, nValue=5 should return 15, which is 1+2+3+4+5

Answer:
#include <iostream>
using namespace std;
int main ()
{
int number, i =1, sum =0;
cout<<“Enter a positive integer”;
cin>> number;
while (i<= number)
{
sum +=i;
++i;
}
cout<<“Sum of ” << number <<“=”<< sum;

return 0;
}
Output:
The output of the program is as follows:

2nd year Computer science Notes Chapter 4 Control Structures
2nd year Computer science Notes Chapter 4 Control Structures 10

Q.7) What is wrong with the following for loop?
// Print all numbers from 9 to 0
for (unsigned int nCount = 9; nCount >=0; nCount –)
cout <<nCount <<” “;

Answer:
PROBLEM:
The problem in the loop is that an unsigned number is never negative.
Therefore, the loop-test nCount >= 0 will always be true. Thus you get an infinite loop.
The output of the infinite loop with the above mentioned code is as follows:

fg
2nd year Computer science Notes Chapter 4 Control Structures 11

Q.8) Write a C++ program to read the address of a person and exit when the user enters dot (.) from the keyboard.

Answer: 
#include <iostream>
using namespace std;
int main()
{
char ch;
cout << “Enter address : ” << endl;
ch = _getche();
while (ch != ‘.’)
{
ch = _getche();
}
cout << “\n\n\n”;
cout << “You pressed dot(.)” <<“\n\n\n”;
return 0;
}
Output:
The output of the above program is as follows:

fgsad
2nd year Computer science Notes Chapter 4 Control Structures 12

Q.9) Write a C++ program to find out the area of a triangle and if any side is zero then display the message “There is no triangle”.

Answer:
#include<iostream>
using namespace std;
int main ()
{
int height, base;
float ans;
cout <<“Enter height and base:”;
cin>>height>> base;
ans=(0.5)*height*base;
if (height == 0 ||base==0)
cout<< “there is no triangle”;
else
cout<<“Area of triangle is :<<ans;
return 0;
}
Output:
The output of the above program is as follows:

sdf
2nd year Computer science Notes Chapter 4 Control Structures 13

Q.10) Write a C++ program to input a character from the keyboard and display the message after testing whether it is Vowel or Consonant.

Answer: 
PROGRAM TO CHECK WHETHER ENTERED CHARACTER IS VOWEL OR CONSONANT:
#include<iostream>
using namespace std;
int main ()
{
char c;
int isLowercaseVowel , isUppercaseVowel;
cout<<“Enter an alphabet:”;
cin>> c;
isLowercaseVowel =( c== ‘a’ || c==’e’ || c==’i’ || c==’o’ ||c==’u’);
isUppercaseVowel =( c==’A’ || c==’E’ || c==’I’ || c== ‘O’ || c==’U’);
if (isLowercaseVowel || isUppercaseVowel)
cout<<c<< ”     is a Vowel”;
else
cout<< c<< ”    is a consonant”;
return 0;
}
Output:
The output of the above program is as follows:

fdgfd
2nd year Computer science Notes Chapter 4 Control Structures 14

Reated Post:

  • 2nd-year computer science notes Chapter 1 Operating Systems
  • 2nd-year computer science notes Chapter 2 System Development Life Cycle
  • Chapter 3 Object-Oriented Programming using C++

What are the 3 types of control structures?

The flow of authority through any given part is implemented with 03 essential types of control systems:
Sequential: defaulting mode. …
Selection: used for decisions, branching — selecting between 2 or more alternative paths. …
Repetition: operated for looping, i.e. repeating a portion of code multiple times in a row.
Visit Now

SendShareTweetPin4ShareShareShareShareSend
Previous Post

Chapter 3 Object Oriented Programming using C++

Next Post

2nd Year Computer Science Notes Chapter 5 Arrays and Strings

RelatedPosts

KPK G12 Computer Science Notes Chapter 6 (Functions)
2nd year computer science notes

KPK G12 Computer Science Notes Chapter 6 (Functions)

39

The best Notes for exam preparation of 2021-22 kpk class...

Read more
Best 2nd Year Computer Science Notes of All Chapters

Best 2nd Year Computer Science Notes of All Chapters

220
Class 12 Computer Science Notes for KPK Chapter 9 File Handling

Class 12 Computer Science Notes for KPK Chapter 9 File Handling

34
Chapter 8 Objects and Classes

2nd year Computer Science Notes Chapter 8 Objects and Classes

81
Load More
Please login to join discussion
No Result
View All Result

Top Posts & Pages

  • Download file
  • KPK Text Book Board New 2021 PDF Download
  • Sindh textbook board Jamshoro books pdf download 2021
  • Download All Classes Notes in Pdf Class 9, Class 10, Class 11, & Class 12
  • Adamjee Islamiat Compulsory 9th Model Papers
  • Biology 9th Adamjee Model Paper 2021
  • Adamjee Sindhi Salees 10th Model Paper for New Pattern 2022
  • Sindh 9th Class Islamiat Notes PDF Download Urdu | Eng Medium

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 742 other subscribers

  • Trending
  • Comments
  • Latest
Sindh textbook board Jamshoro books pdf download

Sindh textbook board Jamshoro books pdf download 2021

KPK Text Book Board

KPK Text Book Board New 2021 PDF Download

9th Class Math Notes PDF Download Cha 1 to 9

Top 9th Class Math Notes PDF Download Cha 1 to 9

Class 12 English notes Lesson 1 to 20

Class 12 English notes Lesson 1 to 20 for KPK

Best Mothers Day Essay in English USA Gift Movie

Best Mothers Day Essay in English | USA | Gift | Movie

short essay on corruption in pakistan | essay on corruption with quotations | essay on corruption with outline | essay on corruption 500 words | essay on corruption in pakistan pdf | corruption essay pdf

500 Word Essay on Corruption In English

Essay on Co Education

Essay on Co Education – 500 Words

Visit the zoo Essay

Visit the zoo Essay

work and energy ch 6 physics g9 bise rawalpindi ex

Work and Energy Cha 6 Physic G9 Bise Rawalpindi

Gravitation Physics Cha 5 Bise Rawalpindi

Gravitation Physics G9 Cha 5 Bise Rawalpindi

Turning Effect of Forces Physics G9 Bise Rawalpindi Cha 4

Turning Effect of Forces Physics G9 Bise Rawalpindi Cha 4

Dynamics bise Rawalpindi 9th Physics Class Mcqs Notes Problems

Dynamics bise Rawalpindi 9th Physics Class Mcqs Notes Problems

Recent Posts

  • Work and Energy Cha 6 Physic G9 Bise Rawalpindi
  • Gravitation Physics G9 Cha 5 Bise Rawalpindi
  • Turning Effect of Forces Physics G9 Bise Rawalpindi Cha 4
  • Dynamics bise Rawalpindi 9th Physics Class Mcqs Notes Problems
  • Physics Cha 2 Kinematics Grade 9 Notes Rawalpindi Board
  • Home
  • Privacy Policy
  • Subscription
  • Contact us
  • Feedback
  • Disclaimer
  • Terms & Conditions
  • Cookies Policy
  • ABOUT US
  • Newsletter

© 2021 Perfect24u | All Rights Reserved

No Result
View All Result
  • Home
  • KPK NOTES
    • KPK TextBook Board
      • Grade 1
      • Grade 2
      • Grade 3
      • Grade 4
      • Grade 5
      • Grade 6
      • Grade 7
      • Grade 8
      • Grade 9
      • Grade 10 KPTBB BOOK
      • Grade 12 books for KPK
      • Grade 11 BOOK KPK Board
    • Class 7
      • Urdu
    • Class 9
      • Mathematics
      • English Class 9 Notes for KPK
      • 9th Urdu Notes
      • Biology 9th
      • Islamiat 9
      • Computer Science 9th
      • Pak Studies 9
      • Physics 9th
      • Chemistry 9th
    • Class 10
      • English 10th Notes
      • Biology 10 Class
      • CHEMISTRY 10 NOTES
      • class 10 Maths
      • Pak Study 10th
      • Physics 10
      • Urdu 10
    • Class 11 KPK Notes
      • 11 class biology notes KPK
      • 1st Year Mathematics Notes
      • chemistry class 11 notes
      • English FA Fsc Part 1 KPK
      • Islamiat Class 11 for kpk
      • Physics class 11 notes
    • 2nd Years
      • 2nd Year Chemistry Notes
      • Mathematics-XII
      • 2nd year computer science notes
      • 2nd Year Economics Notes
      • 2nd year English notes
      • 2nd year Pakistan Study Notes
      • 2nd Year Physics Notes
      • Bio Fsc Part 2
    • BISE Swat
      • Result
      • Model Papers
      • Chemistry Class 10 Notes
      • Class 11 Computer Science
      • Economics Notes Class 11
      • Statistics Class 11
      • Class 12 Statistics Notes
    • Syllabus
    • Mardan Board
      • 9th Notes
  • AIOU
    • B.ED books
    • B.S AIOU Books
    • Bachelor AIOU Books
    • CT AIOU Books
    • FA
  • BISE Lahore
    • Class X
      • English Class 10th Notes
    • Class IX
      • English Class 9th Notes
    • Class XI
      • English Class 11th Notes
    • Class XII
      • English Class 12th Notes
  • Sindh Board
    • Sindh Textbook Jamshoro
    • Class IX
      • Pak Studies Sindh 9
      • Computer Science 9 Sindh
      • Mathematic Sindh Class 9
      • Chemistry Notes
      • Biology 9
      • Physics
      • Sindh Board English 9th Notes
      • Islamiat Class 9 Sindh
    • Class X
      • Sindh Class 10 Physics
      • Sindh Class 10th English Notes
      • Islamiat Class 10 Sindh
    • Class XI
      • Islamiat
      • English notes class 11 Sindh board
    • Class XII
      • English Notes Sindh board 12th
  • CBSE
    • CBSE Class 9
    • CBSE Class 10
    • CBSE Class 11
    • CBSE Class 12
  • Rawalpindi Board
    • Class 9th
      • English 9th Notes
      • Biology G9
    • Class 10th
      • English 10th Notes
    • Class 11th
      • English 11th Notes
  • FBISE
    • 9 Class
      • Computer Science
      • Biology Notes
      • 9th FBISE Maths
      • Fbise 9 Notes Eng
    • 10 Class
      • English FBISE Notes
    • 11 Class
      • FBISE English 11th
    • 12 Class
      • Class 12 English Notes Fbise
    • FBISE Past Papers
      • 10 Class
      • 9th Past Papers
  • Articles
    • Essay
    • A-Z Universities in Pakistan
    • Admissions
    • All Country Independence Day
    • Countries Info
    • FILMORA
    • Education Qoutes
    • Happy Teacher Day
    • Insurance
    • Islamic
    • Muslim Boys names
    • Nelson’s Mandela
    • PHILONTHROPIC PRACTICES
    • Speeches
    • Story
  • DIT
  • DAE
  • MCQs
  • Technology
    • Marketing Think with Google
    • Science
  • Punjab board
    • Class 11 Notes PTBB
      • Computer Science PTBB Class 11
      • English 11 Notes Punjab
      • Chemsitry PTBB 11th
      • Math Notes PTBB 11th
      • Physics PTBB 11th
      • Urdu PTBB 11th
      • Biology 11th PTBB
    • Class 9
    • Punjab Class 10th
    • Punjab Board Class 10 Chemistry

© 2021 Perfect24u | All Rights Reserved

 

Loading Comments...
 

You must be logged in to post a comment.