Technocrat

  • Home
Showing posts with label CPP. Show all posts
Showing posts with label CPP. Show all posts

Thursday, November 27, 2014

Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle

 Sumit Kar     November 27, 2014     C++ Programming, CPP     No comments   



Sumit Kar, Timus Rak,CPP



/* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */

#include 
using namespace std;
class Rectangle
{
    protected:
       float length, breadth;
    public:
        Rectangle(): length(0.0), breadth(0.0)
        {
            cout<<"Enter length: ";
            cin>>length;
            cout<<"Enter breadth: ";
            cin>>breadth;
        }

};


/* Area class is derived from base class Rectangle. */

class Area : public Rectangle   
{
    public:
       float calc()
         {
             return length*breadth;
         }

};


/* Perimeter class is derived from base class Rectangle. */

class Perimeter : public Rectangle
{
    public:
       float calc()
         {
             return 2*(length+breadth);
         }
};

int main()
{
     cout<<"Enter data for first rectangle to find area.\n";
     Area a;
     cout<<"Area = "<
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Wednesday, November 12, 2014

Implement array of Objects using C++

 Sumit Kar     November 12, 2014     C++ Programming, CPP     No comments   



Write a Program in C++ to implement array of Objects. Take the
user input of Name of player, Age and score. Sort the data based on the highest
Scores.





Program:





#include<iostream.h>


#include<conio.h>


#include<string.h>





class det


{


 public:


 int age,score;


 char name[20];


 void input();


 void show();


 void init();


};


 void det::init()


 {


  age=0;


  score=0;


  char name1[20]="Blank";


  strcpy(name,name1);


 }


 void det::input()


       {





      
cout<<"Enter the Name: ";


      
cin>>name;


      
cout<<"Enter the Age: ";


      
cin>>age;


      
cout<<"Enter the score: ";


      
cin>>score;


       }


 void det::show()


       {


      
cout<<" Name  : "
<<name;


      
cout<<"\t Age   :
" <<age;


      
cout<<"\t Score : " <<score
<<endl<<endl<<endl;


       }








int
main()


{


 int i,n=0,j,choice,index,count=0;


 char ch;


 det a[10],temp;


 clrscr();





 for(i=0;i<10;i++)


  a[i].init();





 do


 {


  cout<<" : : Menu : : ";


 
cout<<"\n1.Add\n2.Edit\n3.Delete\n4.Sort\n5.Print\n0.Exit"<<endl;


  cout<<"Enter Choice: ";


  cin>>choice;


  switch(choice)


  {


  case 1:


     ch=121;


     for(i=n;i<=10;)


        {


        
if(ch==121||ch==89)


          
{


           
a[i].input();


            count++;


           
cout<<"Add more?(Y/N) :";


           
cin>>ch;


           
i++;


          
}


        
else


          
break;


         }


        
n=count;


     break;





  case 2:


     for(i=0;i<n;i++)


        {


        
cout<<i+1;


        
a[i].show();


        }


     cout<<"Enter the Index to be
edited:";


     cin>>index;


     a[index-1].input();


     cout<<"Updated \n\n";


     break;


  case 3:


      for(i=0;i<n;i++)


        {


        
cout<<i+1;


        
a[i].show();


        }


     cout<<"Enter the Index to be
deleted:";


     cin>>index;





     if ( index >= n+1 )


      
cout<<"Deletion not possible.\n";


     else


      {


       for
( i = index - 1 ; i < n - 1 ; i++ )


         
a[i] = a[i+1];


      
n=n-1;


      
cout<<"Deleted\n\n";


      
break;


     }


  case 4:


     for (i=0;i<n;i++)


         {


         
for(j=i+1;j<n;j++)


          {


           if (a[j].score>a[i].score)


             
{


             
temp=a[i];


             
a[i]=a[j];


              a[j]=temp;


             
}


           }


         
}


      cout<<"Sorted\n\n"<<endl;


      break;


  case 5:cout<<endl<<endl;


     for(i=0;i<n;i++)


        {


        
a[i].show();


        }


     break;


  case 0:cout<<"Program
Terminated... Press Any key to Exit!";


     break;


  default : cout<<"Wrong Choice";





 }


}while(choice!=0);


 getch();


 return 1;


}







Output:






Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Print Details using C++

 Sumit Kar     November 12, 2014     C++ Programming, CPP     No comments   



Write a Program in C++ to print the details.








#include<iostream.h>


#include<conio.h>


#include<stdio.h>


#include<string.h>


class Details


{


 public:





 void
person(char[],int,int,int);


};





inline void Details :: person(char name[],int
id,int dob,int marks)


{


 cout<<"Name : ";


 puts(name);


 cout<<"ID : "<<id;


 cout<<"Date of birth :
"<<dob;


 cout<<"Marks : "<<marks;


}





int main()


{


 Details ob;


 char
name[10];int dob,id,marks;


 cout<<"Enter your name: ";


 gets(name);


 cout<<"Enter your ID: ";


 cin>>id;


 cout<<"Enter your Date of Birth:
";


 cin>>dob;


 cout<<"Enter your marks: ";


 cin>>marks;


 ob.person(name,id,dob,marks);


 getch();


 return
0;


 }








Output:


Enter your name: Sumit


Enter your ID: 55


Enter your Date of Birth: 14031994


Enter your marks: 65


Name : Sumit


ID: 55


Date of birth: 14031994




Marks: 65


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Find the Size of a Class and object in C++

 Sumit Kar     November 12, 2014     C++ Programming, CPP     No comments   



Write a Program to find the Size of a Class
and object.





#include <iostream.h>


#include <conio.h>





 class
SI


  {


  
public:


   
double p,t,r;


   
void interest(double,double,double);


  };





 inline
void SI :: interest(double a, double b, double c)


   {


   
double i,sum;


   
p=a;


   
t=b;


   
r=c;


   
i=(p*t*r)/100;


   
sum=p+i;


   
cout<<"\nThe Interest is: "<<i;


   
cout<<"\nThe Sum is: "<<sum;





   }





 int
main()


  {


 
double principal,time,rate;


 
clrscr();


 
cout<<"Principal: ";


 
cin>>principal;


 
cout<<"Time: ";


 
cin>>time;


 
cout<<"Rate: ";


 
cin>>rate;


  SI
ob;


 
ob.interest(principal,time,rate);


 
cout<<"\nSize of Class: "<<sizeof(SI);


 
cout<<"\nSize of Object: "<<sizeof(ob);


 
getch();


 
return 0;


  }





Output:





Principal: 5000


Time:10


Rate: 10


The Interest is: 5000


The Sum is: 10000


Size of Class: 24


Size of Object: 24










Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Find Simple Interest using C++

 Sumit Kar     November 12, 2014     C++ Programming, CPP     No comments   



Write a Program in C++ to find Simple
Interest.





#include <iostream.h>


#include <conio.h>





 class
SI


  {


  
public:


   
double p,t,r;


   
void interest(double,double,double);


  };





  void
SI :: interest(double a, double b, double c)


   {


   
double i,sum;


   
p=a;


   
t=b;


   
r=c;


   
i=(p*t*r)/100;


   
sum=p+i;


   
cout<<"\nThe Interest is: "<<i;


   
cout<<"\nThe Sum is: "<<sum;


   
getch();


   }





 int
main()


  {


 
double principal,time,rate;


 
clrscr();


 
cout<<"Principal: ";


 
cin>>principal;


 
cout<<"Time: ";


 
cin>>time;


 
cout<<"Rate: ";


 
cin>>rate;


  SI
ob;





 
ob.interest(principal,time,rate);





 
return 0;


  }





Output:


Principal: 5000


Time:10


Rate: 10


The Interest is: 5000


The Sum is: 10000







Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Print the digits of a number in words using C++

 Sumit Kar     November 12, 2014     C++ Programming, CPP     No comments   



Write a Program in
C++ to print the digits of a number in words.











Program:





#include <iostream.h>


#include <conio.h>








 class PNIW


  {


   public:


     void
ntow(int);


     void
display(int);


  };





 void PNIW ::
ntow(int n)


   {


    int
i=0,j=0,temp,sum=0,count=0,ar[10];


    temp=n;


   
while(temp!=0)


     {


     
i=temp%10;


     
ar[count]=i;


      count++;


     
temp=temp/10;


     }


   
for(i=count-1;i>=0;i--)


     {


      j=ar[i];


     
display(j);


     }


   }








 void PNIW ::
display(int i)


   {


    switch(i)


    {


    case
0:cout<<"Zero ";


        break;


    case
1:cout<<"One ";


        break;


    case
2:cout<<"Two ";


        break;


    case
3:cout<<"Three ";


        break;


    case
4:cout<<"Four ";


        break;


    case
5:cout<<"Five ";


        break;


    case
6:cout<<"Six ";


        break;


    case
7:cout<<"Seven ";


        break;


    case
8:cout<<"Eight ";


        break;


    case
9:cout<<"Nine ";


        break;


    default:
cout<<"Error ";


          break;


    }


 }








 int main()


  {


  int num;


  clrscr();


 
cout<<"Enter Number: ";


 
cin>>num;


  PNIW ob;


 
ob.ntow(num);





  getch();


  return 0;


  }








Output:


Enter Number: 990




Nine Nine Zero


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp

Monday, September 8, 2014

Write a Program in C++ to find the Factorial of a Number

 Sumit Kar     September 08, 2014     C++ Programming, CPP     No comments   



Sumit Kar, Timus Rak, Factorial


/*ITERATIVE*/


//Calling the Header File.
#include<iostream>


//Declaring the main function
int main()
{

//Tells the compiler that we'll be using all the standard C++ library functions
using namespace std;
int num,factorial=1;
//Ask for the number.
cout<<"Enter a number to calculate it's factorial"<<endl;
cin>>num;
for(int i=1;i<=num;i++)
{
factorial=factorial*i;
}
cout<<"Factorial of "<<num<<"="<<factorial<<endl;
cin.get();

return 0;
}



/*RECURSION */


#include<iostream>

using namespace std;

int fact(int);
int main(){
int num,f;
cout<<"\nEnter a number: ";
cin>>num;
f=fact(num);
cout<<"\nFactorial of "<<num<<" is: "<<f;
return 0;
}
//recursive function
int fact(int n){
if(n==1)
return 1;
else
return(n*fact(n-1));
}


/*
Summary: Factorial is represented using '!', so five factorial will be written as (5!),n factorial as (n!).Also
n! = n*(n-1)*(n-2)*(n-3)...3.2.1 and zero factorial is defined as one i.e. 0! = 1.
*/


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
  •  WhatsApp
Older Posts Home

Pages

  • Home

Trending Now

  • Write a Program to Add two 3x3 Matrix using C
    #include<stdio.h> void main () { int a [ 3 ][ 3 ], b [ 3 ][ 3 ], s [ 3 ][ 3 ], i , j ; printf ( "Enter the values of ...
  • C program for Unit Conversion
    /* Convert Celsius to Fahrenheit */ #include<stdio.h> void main() {     float c,f;     printf("Enter the temperature in Celcius: ...
  • Addition of two numbers on Server sent from Client [TCP] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • Write a Program to Print the Truth Table of Basic Gates using C
  • Write a Program to Add two 5x5 Matrix using C
    #include<stdio.h> void main() {   int a[5][5],b[5][5],c[5][5];   int i,j;   for(i=0;i<5;i++)   {     printf("\nEnter elements ...
  • Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle
    /* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */ #include using namespace std; class Re...
  • Concatenation of two strings sent from Client on the Server - [ TCP ] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • 8085 Programming: Exchange the contents of memory locations
    Exchange the contents of memory locations 2000H and 4000H. Program 1: LDA 2000H : Get the contents of memory location 2000H into accumulator...
  • Calculate Depreciation using C
    #include<conio.h> #include<stdio.h> void main () { float sv , pv , dep ; int yos ; clrscr (); printf ( "Enter the pu...
  • 8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER
    The 16bit number is stored in C050,C051 The answer is stored in C052,C053   LXI H,C050   MOV A,M   CMA   STA C052   INX H   MOV ...

Blog Archive

  • ▼  2020 (1)
    • ▼  May (1)
      • Automating your deployments using Ansible
  • ►  2015 (92)
    • ►  October (4)
    • ►  September (3)
    • ►  August (3)
    • ►  July (9)
    • ►  June (9)
    • ►  May (20)
    • ►  April (7)
    • ►  March (22)
    • ►  February (7)
    • ►  January (8)
  • ►  2014 (158)
    • ►  November (70)
    • ►  October (6)
    • ►  September (82)
Powered by Blogger.

Categories

C - Programming Java Programming Basic Technology 8085 Assembly Programming For Loop Numerical Methods WhatsApp Algorithm Shell Programming Programming Networking Windows Android C++ Programming CPP If Else Tricky Internet Microsoft Pattern Photography Socket Program News While Loop Array DBMS DS Macro Recursion User Defined Function Conditional Operator Data Structure Durga Puja Earthquake Google Mela Nokia SQL Share Yahoo Airtel Bio Command Prompt Confused Facebook Finance Firefox Ganges Graph HokKolorob Input Kolkata MCQ Math Matrix NetNeutrality Oracle Religion Search Sumit Kar Survey Switch Case Viral Virus Visual Studio do-while featured featured_slider

Popular Programs

  • Write a Program to Add two 3x3 Matrix using C
    #include<stdio.h> void main () { int a [ 3 ][ 3 ], b [ 3 ][ 3 ], s [ 3 ][ 3 ], i , j ; printf ( "Enter the values of ...
  • C program for Unit Conversion
    /* Convert Celsius to Fahrenheit */ #include<stdio.h> void main() {     float c,f;     printf("Enter the temperature in Celcius: ...
  • Addition of two numbers on Server sent from Client [TCP] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • Write a Program to Print the Truth Table of Basic Gates using C
  • Write a Program to Add two 5x5 Matrix using C
    #include<stdio.h> void main() {   int a[5][5],b[5][5],c[5][5];   int i,j;   for(i=0;i<5;i++)   {     printf("\nEnter elements ...
  • Using the concept of Inheritance write a C++ Program to calculate the area and perimeter of rectangle
    /* C++ Program to calculate the area and perimeter of rectangles using concept of inheritance. */ #include using namespace std; class Re...
  • Concatenation of two strings sent from Client on the Server - [ TCP ] using C
    /* tcpClient.c */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #inc...
  • 8085 Programming: Exchange the contents of memory locations
    Exchange the contents of memory locations 2000H and 4000H. Program 1: LDA 2000H : Get the contents of memory location 2000H into accumulator...
  • Calculate Depreciation using C
    #include<conio.h> #include<stdio.h> void main () { float sv , pv , dep ; int yos ; clrscr (); printf ( "Enter the pu...
  • 8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER
    The 16bit number is stored in C050,C051 The answer is stored in C052,C053   LXI H,C050   MOV A,M   CMA   STA C052   INX H   MOV ...

Daily Hits

Copyright © Sumit Kar