Login


Lost your password?

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


Shop
CPP : Showcase: All Recent Posts Grouped
Concept Learning Code Sheets View all
Finding string class string length .length() .size() .c_str() methods #3009  (25-Jan-2018)
In Topic(s) : Strings - string class type   

#include 
#include 
using namespace std;
int main()
{
  string s1="Trees can check pollution.";
  cout<<"String = "<.length() = "<.size() = "<-->
        

Program to demonstrate string class based string in c++ using different methods length() size() and conversion to c_str()


Structure passed as a reference #2979  (24-Jan-2018)
In Topic(s) : Structures passing/returning   

#include 
#include 
using namespace std;
struct Person
{
  char name[40];
  int age;
};

void modify(Person &p,char n[],int a=16)
{
  strcpy(p.name,n);
  p.age=a;
}  

int main()
{
  Person pers={"Lata",16};
  cout<

A program to demonstrate how an structure is passed as a reference argument to a function.



Sum of digits program using a function #2189  (5-Jan-2018)
In Topic(s) : Functions - user defined   

#include 
using namespace std;
int sumofdigits(int);
int main()
{
  int n,s;
  cout<<"Input a number : " ;
  cin>>n;	   
  s=sumofdigits(n);	 
  cout <<"Sum of Digits of "<0)
  {
     rem=n%10;
     s+=rem;	  	  
     n=n/10;
  }
  return s;
}

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


Print till Z with while loop boundary crossing #2038  (30-Dec-2017)
In Topic(s) : Simple Loops   

#include 
using namespace std;
int main()
{
  char ch;
  cout<<"Enter an alphabet :";
  cin>>ch;
  if(ch>=65 && ch<=90) 
    while(ch!=91) cout<< ch++;
  else if(ch>=97 && ch<=122)     
    while(ch!=123) cout<< ch++;
  else cout<<"Entry was not an alphabet"; 
  return 0;
}

As user enters a lower case or upper case alphabet the program prints from that alphabet till z using the faster technique of while loop iteration and checking for outside boundary condition


Print till Z with loop count calculation #2034  (29-Dec-2017)
In Topic(s) : Simple Loops   

#include 
using namespace std;
int main()
{
	char ch;
	int lc;
	cout<<"Enter an alphabet :";
	cin>>ch;
	int n=ch;
	if(n>=65 && n<=90) lc=90-n+1;
	else if (n>=97 && n<=122) lc=122-n+1;
	else {cout<<"Entry was not an alphabet"; return 0;}
	
	for(int i=0;i

As user enters a lower case or upper case alphabet the program prints from that alphabet till z.


For and while loop comparison #1995  (28-Dec-2017)
In Topic(s) : Simple Loops   

#include 
using namespace std;
int main()
{
	for(int i=1;i<=10;i++)
    cout<

Comparing simple for and while loop with a simple number printing example


Checking if character entered is a vowel – switch-case #1973  (28-Dec-2017)
In Topic(s) : Switch case selection   

#include 
using namespace std;
int main ( )
{ 
  char c;
  cout<<"Enter an alphabet(a-z/A-Z) : ";
  cin>>c;
  switch (c)
  {
    case 'A': case 'a':
    case 'E': case 'e':
    case 'I': case 'i':
    case 'O': case 'o':
    case 'U': case 'u': cout <<"It is a vowel";
                        break;
    default: cout <<"It is not a vowel";
  }
  return 0 ;
}

Entering a character from console and then checking if entered character is a vowel or something else.


Territory-wise volume based sales commission – nested if #1945  (27-Dec-2017)
In Topic(s) : Multiple-Nested-Ladder of If Else   

#include 
using namespace std;
int main()
{
  int vol,comm,tt;
  cout<<"Enter territory number (1/2) :";cin>>tt;
  cout<<"Enter sales volume :";cin >> vol;
  if(tt==1)
  {
    if (vol >=1000) comm=10;
    else if (vol <1000 && vol >=500) comm=5;
    else comm=0;
  }
  else if (tt==2)
  {
    if (vol >=1500) comm=10;
    else if (vol <1500 && vol >=700) comm=5;
    else comm=0;
  }
  else comm=0;
  cout<<"The sales commission would be "<

Finding the volume based sales commissions based on multiple territories using the nesting of if conditions


Making a number absolute using If #1861  (22-Dec-2017)
In Topic(s) : Simple If and If Else   

#include 
using namespace std;
int main( )
{
  int n;
  cout<<"Enter a negative or positive integer:";
  cin>>n;
  int on=n;
  if(n < 0) n=- n;
  cout<<"The absolute value of "
      <

A number is made absolute by removing its negative sign if present.


Solved ProblemsView all



Slope of line -using structure Point passed to a function #2973 (24-Jan-2018)
In Topic(s) : Structures passing/returning   

Write a program by declaring a structure Point with two integer values for its position x and y. Now write a function that finds slope of a line drawn out of two points that are passed as structure argument to this function. Show implementation of this function and structure in the main routine assuming suitable values of x and y being initialised for two points.

Write a program by declaring a structure Point with two integer values for i


Counting words in a text input even if it is not well formed #2717 (17-Jan-2018)
In Topic(s) : String Handling (Null Terminated)   

Write a program to count number of words even when there might be extra spaces between words and extra punctuation marks. Any alphabets or numbers written contiguously will be counted as words. For. e.g. “21st Century” are two words and “21    st         century systems ?” are four words. ? is not counted as word while 21 is counted as a word.

Write a program to count number of words even when there might be extra space


Leap year finding #2008 (29-Dec-2017)
In Topic(s) : Multiple-Nested-Ladder of If Else   

Write a c++ program to take the value of a four digit year from the user and then print whether the given year is a leap year or not.

Write a c++ program to take the value of a four digit year from the user and



Linear search function for search term presence and location #1632 (4-Dec-2017)
In Topic(s) : Arrays Concepts and 1-D Arrays   

Write a function linsearch(int [],int, int) which searches for the term 23 in the given integer array [12,19,23,3,2] and returns its position in the array. This array should be initialised in the calling function and then passed as reference to the given function. Show implementation also.

Write a function linsearch(int [],int, int) which searches for the term 23 in