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

KPK G12 Computer Science Notes Chapter 6 (Functions)

ADVERTISEMENT
ADVERTISEMENT

The best Notes for exam preparation of 2021-22 kpk class 12 computer science notes chapter number #6 functions.

Functions computer science notes chapter 6

Table of Contents

  • Functions computer science notes chapter 6
  • Q.4) Write a program with a function that takes two int parameters, adds them together, and then returns the sum.
  • Q.5) Write a program  with a function name “mean” to read in three integers from the keyboard to find the arithmetic mean.
  • Q.6) Write a C++ program having a function name rectangle to read the length and width of a rectangle from the keyboard and find the area of the rectangle. The result should be returned to the main program for displaying on the screen.
  • Q.7) Write a C++ program having two function names area and perimeter to find the area and parameter of a square.
  • Q.8) Write a C++ program to read a number from the keyboard and then pass it to a function to determine whether it is prime or composite.
  • Q.10) Define function and differentiate between built-in and user-defined functions with the help of examples.
  • Q.11) How function prototype and declarator differ from each other? Explain with the help of examples.
  • Q.12) Define default arguments. Describe the advantages and disadvantages of the default argument.

Q.4) Write a program with a function that takes two int parameters, adds them together, and then returns the sum.

Answer:
int sum(int x, int y); // Function prototype/declaration
int main()
{
    int a,b;
    cout << “Enter First Number : “;
    cin >> a;
    cout << “Enter Second Number : “;
    cin >> b;
    int c = sum(a, b);
    cout << “The sum of two numbers is : ” << c << “\n\n\n”;
}
int sum(int x, int y) // Function definition
{
    return (x + y);
}
Output:
The output of the program is as follows:

Figure showing the output of the program
KPK G12 Computer Science Notes Chapter 6 (Functions) 5

Q.5) Write a program  with a function name “mean” to read in three integers from the keyboard to find the arithmetic mean.

Answer:
#include “stdafx.h”
#include <iostream>
#include<conio.h>
using namespace std;
void mean(int x, int y, int z)
{
    int sum,arithMean;
    sum = x + y + z;
    arithMean = sum / 3;
    cout << “Arithmetic Mean = ” << arithMean << “\n\n”;
}
int main()
{
    int a, b,c;
    cout << “Enter FIRST integer : “;
    cin >> a;
    cout << “Enter SECOND integer : “;
    cin >> b;
    cout << “Enter THIRD integer : “;
    cin >> c;
    mean(a, b, c);
    return 0;
}
Output:
The output of the program is as follows:

The output of the program is as follows
KPK G12 Computer Science Notes Chapter 6 (Functions) 6

Q.6) Write a C++ program having a function name rectangle to read the length and width of a rectangle from the keyboard and find the area of the rectangle. The result should be returned to the main program for displaying on the screen.

Answer:
#include “stdafx.h”
#include <iostream>
include<conio.h>
using namespace std;
void rectangle(int length, int width)
{
    int area;
   area = length*width;
   cout << “Area of Rectangle is : ” << area << “\n”;
}
int main()//main program
{
    int L, W;
    cout << “Enter length and breadth of rectangle : “;
    cin >> L >> W;
    rectangle(L, W);
    return 0;
}
Output:
The output of the program is as follows:

fdsf 1
KPK G12 Computer Science Notes Chapter 6 (Functions) 7


Q.7) Write a C++ program having two function names area and perimeter to find the area and parameter of a square.

Answer:
#include “stdafx.h”
#include <iostream>
#include<conio.h>
using namespace std;
void area(int length)
{
    int area;
    area = length*length;
    cout << “Area of Square is = ” << area << “\n\n”;
}
void perimeter(int length)
{
    int perimeter;
    perimeter = 4 * length;
    cout << “Perimeter of Square is = ” << perimeter << “\n\n”;
}
int main()
{
    int L;
    cout << “Enter LENGTH of Square : “;
    cin >> L;
    cout << “\n\n”;
    area(L);
    perimeter(L);
    return 0;
}

return
KPK G12 Computer Science Notes Chapter 6 (Functions) 8

Q.8) Write a C++ program to read a number from the keyboard and then pass it to a function to determine whether it is prime or composite.

Answer:
#include “stdafx.h”
#include <iostream>
#include<conio.h>
using namespace std;
void primeComposite(int num1)
{
    int x;
    for (x = 2; x<num1; x++)
    {
        if (num1%x == 0)
        {
            cout << num1 << ” is a composite number.” << endl;
        }
        else
        {
            cout << num1 << ” is a prime number.” << endl;
        }
    }
}
int main()
{
    int num1;
    cout << “Enter an integer : ” << endl;
    cin >> num1;
    primeComposite(num1);
    return 0;
}
Output:

Enter a positive  integer: 23
23 is a prime number.

Q.10) Define function and differentiate between built-in and user-defined functions with the help of examples.

Answer:
FUNCTION
DEFINITION:
“A function is a group of statements that together perform a task.”
Every C++ program has at least one function, which is main(). Additional functions can be defined in the program. Each function performs a specific task.
DIFFERENCE BETWEEN BUILT IN AND USER DEFINED FUNCTIONS
The differences between Built-in and user-defined functions are as follows:

BUILT IN OR LIBRARY FUNCTIONS                                                                                    USER DEFINED FUNCTIONS
Library functions are Predefined functions.User-defined functions are the function which is created by the user as per his own requirements.
Library functions are part of header file
(such as MATH.h) which is called runtime.
User-defined functions are part of the program which compile runtime
In Library functions, developers give it.In User-defined functions the name of function id decided by user
Library functions are Name of function cannot be changed.In User defined functions name of function can be changed any time
Example : SIN, COS, PowerExample : fibo, mergeme

Q.11) How function prototype and declarator differ from each other? Explain with the help of examples.

Answer:
Function prototype/declaration
Function prototype/declaration is done to tell the compiler about the existence of the function. Function’s return type, its name, and parameter list are mentioned. A function prototype/declaration is used before the main() function. It ends with a semicolon (;). The function prototype is used in C++ program only when the function is defined after the definition of main() function. If the function definition lies before the main() function then there is no need for the function prototype.
Example: 
In the following program the portion in red indicates the function_prototype/declaration.
#include < iostream>
using namespace std;
int sum (int x, int y); // Function prototype/declaration
int main()
{
int a = 10;
int b = 20;
int c = sum (a, b);
cout« c;
}
int sum (int x, int y) // Function definition
{
return (x + y);
}


Q.12) Define default arguments. Describe the advantages and disadvantages of the default argument.

Answer:
DEFAULT ARGUMENTS
When declaring a function we can specify a default value for each of the last parameters. This value will be used if the corresponding argument is left blank when calling to the function. To do this, we simply have to use the assignment operator and a value for the arguments in the function declaration. If a value for that parameter is not passed when the function is called, the default value is used, but if a value is specified this default value is ignored and the passed value is used instead.

Related Post:

  • Chapter #01 computer science Operating Systems
  • Chapter #2 computer science (System Development Life Cycle)
  • Chapter #3 computer science (Object Oriented Programming using C++)
  • Chapter #4 computer science Notes computer science (Control Structures)
  • Chapter #5 computer science Notes (Arrays and Strings)
  • Chapter #7 computer science Notes (Pointers)
  • Chapter #8 computer science Notes (Objects and Classes)
  • Chapter #9 computer science Notes (File Handling)

SendShareTweetPinShareShareShareShareSend
ADVERTISEMENT
Previous Post

Statistics Chapter 8 (Hypergeometric and binomial Probability Distribution)

Next Post

KPK Class 12 Statistics Chapter1 (Normal Distribution)

RelatedPosts

Best 2nd Year Computer Science Notes of All Chapters
2nd year computer science notes

Best 2nd Year Computer Science Notes of All Chapters

200

Computer Science Subject 12th Class ICS Part 2 Notes, Chapter...

Read more
Class 12 Computer Science Notes for KPK Chapter 9 File Handling

Class 12 Computer Science Notes for KPK Chapter 9 File Handling

31
Chapter 8 Objects and Classes

2nd year Computer Science Notes Chapter 8 Objects and Classes

73
2nd Year Computer Science Notes Chapter 7 Pointers

2nd Year Computer Science Notes Chapter 7 Pointers

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

Top Posts & Pages

  • Download file
  • PTBB Pak studies10th class Notes in Urdu pdf notes long questions
  • Sindh textbook board Jamshoro books pdf download 2021
  • Mathematic Sindh Class 9 Notes Chapter 1 to 17 pdf Download
  • KPK Text Book Board New 2021 PDF Download
  • Download All Classes Notes in Pdf Class 9, Class 10, Class 11, & Class 12
  • Class 9th Biology Notes for KPK PDF Downalod 2021
  • Adamjee Class 9 new mathematics book notes pdf

Subscribe to Blog via Email

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

Join 739 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

4 Best kids Magna tiles magnetic building toys

4 Best kids Magna tiles magnetic building toys

Dynamics bise Rawalpindi 9th Physics Class Mcqs Notes Problems

Dynamics bise Rawalpindi 9th Physics Class Mcqs Notes Problems

bise rawalpindi physics class 9 notes

Physics Cha 2 Kinematics Grade 9 Notes Rawalpindi Board

physical quantities and measurement class 9 bise rawalpindi

Cha 1 Physical Quantities, Measurements Physics 9th Bise Rawalpindi

Recent Posts

  • 4 Best kids Magna tiles magnetic building toys
  • Dynamics bise Rawalpindi 9th Physics Class Mcqs Notes Problems
  • Physics Cha 2 Kinematics Grade 9 Notes Rawalpindi Board
  • Cha 1 Physical Quantities, Measurements Physics 9th Bise Rawalpindi
  • Transport G9 Bise Rawlapindi Bio Notes cha 9
ADVERTISEMENT
  • 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.