Posts

Showing posts from February, 2022

access the private and public in c++.

Image
 access the private and public in c++.   #include<iostream> using namespace std; class Employee {     private:     int  a,b,c; public:     int d,e,f;     void setData(int a1,int b1,int c1);     void getData(){     cout<<"The value of a is= "<<a<<"\n";     cout<<"The value of b is= "<<b<<"\n";     cout<<"The value of c is= "<<c<<"\n";     cout<<"The value of d is= "<<d<<"\n";     cout<<"The value of e is= "<<e<<"\n";             cout<<"The value of f is= "<<f<<"\n";             } };    void Employee::setData(int a1 ,int b1, int c1){     a=a1;     b=b1;     c=c1; }     int main() { Employee rajukumar; //rajukumar.a=134; this is private   rajukumar.d=55;   rajukumar.e=878;   rajukumar.f=54;   rajukumar.setData(3,4,66);   rajukumar.getData();   return 0;     }

implement class and object(c++)

Image
implement class and object #include<iostream> using namespace std; class item {     int number;// private by default     float cost;//privale by defaault     public:     void getdata(int a ,float b);  //prototype declaration to be defined //............function defined in class.......... void putdata(void)  {      cout<<"number:"<< number<<"\n";      cout<<"cost:"<<cost <<"\n";  } }; //............member function definetion >>..............        void item::getdata(int a ,float b)//use membership label {     number =a;// private variable directly used     cost=b; } //..............main program..............     int main() {     item x;     cout<<"\n object x "<<"\n";     x.getdata(100,299.95); // call number function     x.putdata(); // call number function     item y; //create another object     cout<<"\n object y "<<"\n";     y.getda

Write a program to print out all armstrong numbers between 1 to 500 . If sum of cube of each digit of the number is equal to the number itself then the number is called Armstrong number for example 153 = (1*1*1)+(5*5*5)+(3*3*3).

Image
Write a program to print out all Armstrong numbers between 1 to 500 . If sum of cube of each digit of the number is equal to the number itself then the number is called Armstrong number for example  153=(1*1*1)+(5*5*5)+(3*3*3). #include<stdio.h> #include<conio.h> #include<math.h> int main() { int num,temp,rem=0,sum=0,i; float cube; temp =1; for(i=1;i<500;i++) { while(num!=0) { rem=num%10; cube=pow(rem,3);//or we can write (rem*rem*rem) sum =sum+cube; num=num/10;//here the value of  num =0 } if(sum==temp) priintf("%d\n",temp); //set default values to the variables rem=0; sum=0; cube=0; //increment temp and  num value according to i //for the first loop i=1 temp=i+1; num=i+1; } } OR #include<stdio.h> #include<conio.h> #include<math.h> int main() { int num,temp,rem=0,sum=0,i; float cube; temp =1; for(i=1;i<500;i++) { while(num!=0) { rem=num%10; cube=pow(rem,3); //or we can write (rem*rem*rem) sum =sum+cube; num=num/10;//here the value of

write a program to the ASCII values and their eqivalent character using a while loop the ASCII values vary from 0to 255.

Image
  write a program to the ASCII values and their  equivalent character using a while loop the ASCII values vary from 0to 255. #include<stdio.h> #include<conio.h> int main() { int i; char ascii; for(i=0;i<=255;i++) { printf("%c=%d\n",i,i); } }  

Write a program using reference variables a argument to swap the value of a pair of a integers of C++.

Image
  Write a program using reference variables a argument to swap the value of a pair of a integers   #include<iostream> using namespace std; void swap(int&x,int&y) { int temp; temp =x; x=y; y=temp; } int main(){ int a,b; cout<<"Enter the value of a"; cin>>a; cout<<"Enter the value of b"; cin>>b; cout<<"\n"<<"Before swapping:"; cout<<" a="<<a<<"and b = "<<b; swap(a,b);  cout<<"\n"<<"After swapping:";  cout<<" a="<<a<<"and b = "<<b; } or  👇👇👇👇👇👇👇👇👇👇👇👇👇   #include<iostream> using namespace std; void swap(int&x,int&y) { int temp; temp =x; x=y; y=temp; } int main(){ int a,b; cout<<"Enter the value of a:"; cin>>a; cout<<"Enter the value of b:"; cin>>b; cout<<"\n"<<"Before swapping:"; co