Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  


Shop
CPP All : Functions - user defined
Concept Learning Code Sheets

Function with single parameter to evaluate an expression #2179

Writing a function with one parameter to evaluate an expression.

Area, circumference of circle using two functions #2182

Finding and area and circumference of a circle using two separate functions for each of them

Sum of digits program using a function #2189

Writing function sumofdigits() to add the digits in any integer number and then using this function in the main function.

Repeated display function without any returned value – void type #2214

Function to repeat a character in display for number of times desired.

Setting default parameters in function prototype #2243

The default parameters in function becomes active when given parameter value is not passed. Here we learn this setting at the level of function prototype.

Setting default parameters in function definition #2250

The default parameters in function becomes active when given parameter value is not passed. Here we learn this setting at the level of function definition.

Using constant argument/parameter in a function #2255

Writing a program to find student division using the const argument for maximum marks.

Function polymorphism/overloading based on parameter count #2258

Writing polymorphic function based on difference on number of parameters.

Function polymorphism/overloading based on parameter data type #2263

Writing polymorphic function based on difference on parameters data type.

Function in function calls using salary preparation example #2375

Using the example of salary preparation for building related functions and using function in function calls.

Multiple return paths in isPrime() function for prime number series #2449

Using a bool output function isPrime() which has multiple return paths for prime number check and then using this function to print a prime series for given number of terms

Exam Paper Problems

Sum of even and odd values in an array #5270

( As In Exam - CBSE12A-2018 )

Write the definition of a function SumEO(int VALUES[], int N) in C++, which 

Write the definition of a function SumEO(int VALUES[], int N) in C++, which should display the sum of even values and sum of odd values of the array separately.

Example: if the array VALUES contains
25 20 22 21 53

Then the functions should display the output as:
Sum of even values = 42 (i.e 20+22)
Sum of odd values = 99 (i.e 25+21+53)

Random Number Based Guessing of output of a 2D Array printing #5322

( As In Exam - CBSE12A-2017 )

Look at the following C++ code and find the possible output(s) from the

Look at the following C++ code and find the possible output(s) from the
options (i) to (iv) following it. Also, write the maximum values that can
be assigned to each of the variables N and M.

Note:

  • Assume all the required header files are already being included in
    the code.
  • The function random(n) generates an integer between 0 and n-1
void main()
{
  randomize();
  int N=random(3),M=random(4);
  int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};
  for(int R=0; R<N; R++)
  {
    for(int C=0; C<M; C++)
      cout<<DOCK[R][C]<<" ";
    cout<<endl;
  }
}

(i)
1 2 3
2 3 4
3 4 5

(ii)
1 2 3
2 3 4

(iii)
1 2
2 3

(iv)
1 2
2 3
3 4

01D #5614

( As In Exam - CBSE12A-2016 )

Find and write the output of the following C++ program code:
Note: Assu

Find and write the output of the following C++ program code:
Note: Assume all required header files are already included in the program.

typedef char TEXT[80];
void JumbleUp(TEXT T)
{
  int L=strlen(T);
  for (int C=0;C<L1;C+=2)
{
  char CT=T[C];
  T[C]=T[C+1]
  T[C+1]=CT;
}
  for (C=1;C<L;C+=2)
  if (T[C]>='M' && T[C]<='U')
  T[C]=’@’;
}
void main()
{
  TEXT Str="HARMONIOUS";
  JumbleUp(Str);
  cout<<Str<<endl;
}

Random picking from string array #5621

( As In Exam - CBSE12A-2016 )

Look at the following C++ code and find the possible output(s) from the optio

Look at the following C++ code and find the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the minimum values that can be assigned to the variable PICKER.

Note:
– Assume all the required header files are already being included in the code.
– The function random(n) generates an integer between 0 and n-1

void main()
{
  randomize().
  int PICKER.
  PICKER=1+random(3).
  char COLOR[][5]={"BLUE","PINK","GREEN","RED"}.
  for(int I=0;I<=PICKER;I++)
  {
    for(int J=0;J<=I;J++)
      cout<<COLOR[J].
    cout<<endl.
  }
}
(i) (ii) (iii) (iv)
PINK BLUE GREEN BLUE
PINKGREEN BLUEPINK GREENRED BLUEPINK
PINKGREENRED BLUEPINKGREEN BLUEPINKGREEN
BLUEPINKGREENRED

01D-2017 #6083

( As In Exam - CBSE12D-2016 )

Find and write the output of the following C++ program code:
Note: Assu

Find and write the output of the following C++ program code:
Note: Assume all required header files are already included in the program.

typedef char STRING[80];
void MIXITNOW(STRING S)
{
  int Size=strlen(S);
  for (int I=0;I<Size-1;I+=2)
  {
    char WS=S[I];
    S[I]=S[I+1];
    S[I+1]=WS;
  }
  for (I=1;I<Size;I+=2)
    if (S[I]>='M' && S[I]<='U')
      S[I]=’@’;
}
void main()
{
  STRING Word="CRACKAJACK";
  MIXITNOW(Word);
  cout<<Word<<endl;
}

 

Solved Problems

Simple interest program with function. #2386

Write a c++ program to define a function si(p,r,t) with input parameters as p

Write a c++ program to define a function si(p,r,t) with input parameters as p, r and t for principal, rate and term and let it return no data. The calculated value of interest may be saved in a global variable.
Also show the demonstration of working of this function by calling it in the main() routine by passing some fixed values of p,r and t. In the main routine print the final amount by adding the interest to the principal amount.

Simple Interest function with default parameter values. #2661

Write output of the following program. Please do take care about the default

Write output of the following program. Please do take care about the default parameters given while calling the function.

Trailing default parameters check #2666

A c++ program given here has some errors. Please correct the errors to make i

A c++ program given here has some errors. Please correct the errors to make it a working program. Assume any data values required to make it working correctly.

Function to return largest of three numbers along with all same check #2951

Write a function to return the largest of three integer numbers passed to it

Write a function to return the largest of three integer numbers passed to it as value. Also pass a variable as reference which will be set to 1 if all the numbers passed are same. Show implementation of this function in the main routine with appropriate messages.

Function overloading for area functions #2990

Write a c++ program using function overloading using the following prototype

Write a c++ program using function overloading using the following prototype –
int area(int); //For area of square
float area(float); //For area of circle
int area(int,int); //For area of rectangle
show working of this program by calling this function into the main routine using some assumed valued.

Test palindrome for an integer number #3082

Write a program where a function of prototype int ispalin(int) is written, wh

Write a program where a function of prototype int ispalin(int) is written, which returns 1 when
given input number is a palindrome (eg. 121, 16561) else returns 0. Show implementation of this function in main routine by collecting a positive integer from the user.

function to reverse an integer #3086

Write a program to reverse the given integer number.using a separately called

Write a program to reverse the given integer number.using a separately called function to reverse the number.

Error finding in function and related code #4447

Find syntactical errors in the following program and rewrite the program afte

Find syntactical errors in the following program and rewrite the program after underlining the corrected portion.

#include<iostreamh>
using namespace std;
void toUpper(char x) {return ((char) (x+1));}
main()
{
char c, String[]=”DOGS ARE NOT CATS”;
for(int i=0;String[i]!=;i++)
if(String[i]==’ ‘) cout<<endl;
else { c=toUpper(String[i]);cout<<c;}
return 0;
}

Finding student division using a function #5032

Write a function named DIVISION to pass maximum marks and marks obtained by

Write a function named DIVISION to pass maximum marks and marks obtained by a student. Return division as integer value 1, 2 3 or 0 as follows

=60 % as first division – return 1
>=45 <60 % as Second Division – return 2
>=33 <45 % as Third Division – return 3
<33 as Fail – return 0

Show implementation of above function in main routine with some fixed values.

Function for Addition of Series of Numbers Increasing by 10 #5354

Write a function to find the sum of following series with any looping stateme

Write a function to find the sum of following series with any looping statement
12 + 22 + 32 ……… +72

Quizzes

Code Sheets:11  Exam Paper Problems:5  Solved Problems:10  Quizzes:2
×
Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues


Back