Posts

Showing posts from January, 2022

compute value of one number raised to another in c

Image
 compute value of one number raised to another in c  #include<stdio.h> int main() { float x,power; int y, i ; printf("\n Enter two number :"); scanf("%f%f",&x<&y); power =i=1; while(i<=y) { power=power*x; i++; } printf("%f to the power %d is %f\n",x,y,power); retrun 0; }  or  //compute value of one number raised to another in c  #include<stdio.h> int main() { float x,power; int y, i ; printf("\n Enter two number :"); scanf("%f%f",&x,&y); power =i=1; while(i<=y) { power=power*x; i++; } printf("%f to the power %d is %f\n",x,y,power); return 0; }       related program 1 . whether a character entered through the keyboard is a special symbol or not 2 . calculate of simple interest for 3 sets of p,n and r.. 3 . Demonstrates the use of new and delete operators for dynamic allocation and de-allocation of memory of C++.  4. calculation of factorial value of a number in c.  

calculation of factorial value of a number in c.

Image
 calculation  of factorial value of a number in c..  #include<stdio.h> int main() { int num , i,fact; printf("Enter the the number"); scanf("%d",&num); fact=i=1; while(i<=num) { fact=fact*i; i++; } printf("Factorial value of %d=%d\n",num,fact); return 0; } or   #include<stdio.h> int main() { int num , i,fact; printf("Enter the the number:"); scanf("%d",&num); fact=i=1; while(i<=num) { fact=fact*i; i++; } printf("Factorial value of %d = %d\n",num,fact); return 0; } output--     related program- 1- Determine overtime pay of 10 employees in c program 2 .   Demonstrates the use of new and delete operators for dynamic allocation and de allocation of memory of C++.  3 . calculate of simple interest for 3 sets of p,n and r.. 4 . whether a character intered through the keyboard is a special symbol or not .

illustrate the use of end1 and setw (Use of manipulator) of C++.

Image
 illustrate the use of end1 and setw (Use of manipulator) #include<iostream > #include<iomanip>   //for setw using namespace std; int main() { int Basic=950,Allowance=95,Total=1045; cout<<setw(10)<<"Basic="<<setw(10)<<Basic        <<setw(10)<<"\nAllowance"<<setw(10)<<Allowance       <<setw(10)<<"\nTotal"<<setw(10)<<Total; return 0; }

illustrate the use of new aand delete operations fordynamic allocation for class object the program uses bad_alloc exception instead of null pointer for handling allocation failure of C++

Image
 illustrate the use of new and delete operations for dynamic allocation for class object the program uses bad_alloc  exception instead of null pointer for handling allocation failure #include<iostream> using namespace std; class sample { private: int data1; char data2; public: void set (int i,char c) { data1=i; data2=c; } void display(void) { cout<<"Data1="<<data1;   cout<<"\nData2="<<data2; } }; int main(){ sample *s_ptr; try { s_ptr =new sample; } catch(bad_alloc ba)  { cout<<"Bad Allocation occurred.... the program will be terminate now..."; return 1; } s_ptr-> set(25,'A'); s_ptr-> display(); delete s_ptr; return 1; } output--

Determine overtime pay of 10 employees in c program

Image
  determine overtime pay of 10 employees #include<stdio.h> int main()  { float otpay; int hour,i=1; while (i<=10)  //loop for 10 employees { printf("\n Enter no. of hours worked:"); scanf("%d",&hour); if(hour>=40) otpay=(hour-40)*12; else otpay =0; printf("Hours=%d overtime pay =Rs.%f\n",hour,otpay); i++; } return 0; }  

Demonstrates the use of new and delete operators for dynamic allocation and deallocation of memory of C++.

Image
 Demonstrates the use of new and delete operators for dynamic allocation and deallocation of memory of C++.   use of new and delete operators   #include<iostream> using namespace std; int main(){ int *arr; int size; cout<<"Enter the size of  integer array :"; cin>>size; cout<<"Creating an array of size "<<size"<< . ."; arr=new int[size]; cout<<"\n Dynamic allocation of memory for array is successful."; delete  arr; return 0; } output -- Enter the size of  integer array: 9   Creating an array of size: 9.. Dynamic allocation of memory for array is successful  

calculate of simple interest for 3 sets of p,n and r..

Image
 calculate  of simple interest for 3 sets of p,n and r.   #include<stdio.h> #include<conio.h> void main() { int p,n,count=1; float r,si; clrscr(); while(count<=3) { printf(“Enter value for p,n & r\n\n”); scanf(“%d%d%f”,&p,&n,&r); si=(p*n*r)/100; printf(“\nSimple Interest =%f”,si); count++; } getch(); } or   #include<stdio.h> int main() { int p,n,count=1; float r,si; while(count<=3) { printf("\nEnter value p:"); scanf("%d",&p); printf("Enter value n:"); scanf("%d",&n); printf("Enter value r:"); scanf("%f",&r); si=(p*n*r)/100; printf("\nSimple Interest = %f",si); } count++; return 0; } output--

Scope resolution operator of c++ example

Image
 Scope resolution operator example  #include<iostream> using namespace std; int m=10;   //global m int main() {     int m=20;  // m redeclared  local to main     {     int k=m;  //m declared again     int m=30;  // local to inner block     cout<<"we are in the inner block\n";     cout<<"k="<< k<<"\n";         cout<<"m="<<m<<"\n";     cout<<"::m="<<::m<<"\n";         cout<<"::m="<<::m<<"\n";     cout<<"::m="<<::m<<"\n";     }     cout<<"\nwe are in outer block \n";     cout<<"m="<<m<<"\n";     cout<<"::m="<<::m<<"\n";         cout<<"::m="<<::m<<"\n";     return 0; }    

whether a character intered through the keyboard is a special symbol or not

Image
 whether a character entered through the keyboard is a special symbol or not #include<stdio.h  int main(){ char ch; printf("Enter a character \n"); scanf(""%c",&ch); ((ch>=0 && ch<=47)|| (ch>=58&&ch<=64)|| (ch>=91&&ch<=96)|| (ch>=123))? printf("character entered is a special symbol\\n): printf("character entered is not a special symbol\\n); return 0; }    Enter a character:  @  character entered is a special symbol    related program-- 1.. whether the character Entered through the keyboard is a lower case alphabet or not 2.. The body mas index (BMI) is defined as ratio of the weight of the person (in kilometer) to the square oef height (in meters) . write a program that receive weight and height calculate the BMI and report the BMI category as per the following table . 3.. A certain grade of steel is graded according to following condition: (i) Hardness must be greater than 50. (ii)carbon conte

whether the character Entered through the keyboard is a lower case alphabet or not

Image
  whether the character Entered  through the keyboard is a lower case alphabet or not   #include<stdio.h> int main() { char ch; //Input character from user  printf("Enter any character:"); scanf("%c",&ch); if(ch>='A'&&ch<='Z') { printf("%c is Uppercase alphabet.",ch); } else if(ch>='a'&&ch<='z) { printf("%c is lowercase alphabet",ch);  } else {  printf("%c is not alphabet",ch); } return 0; } . output Enter any character:U  is Uppercase alphabet . related example-- 1.. A digital world colors are specified in Red ,Green ,Blue(RGB) format with value of (R,G,B) varying on integers scale from 0 to 255 in point publishing the colors are mentioned in cyan, magenta - yellow black (CMYK) format ,with value of C,M,Y and k varying on real scale from 0.0 to 1.0 write the program to convert RGB colors to CMYK as per the following formula.. White=max(Red/255,Green/255,Blue/255), cyan

The body mas index (BMI) is defined as ratio of the weight of the person (in kelometer) to the square oef height (in meters) . write a program that recieve weight and height calculate the BMI and report the BMI category as per the following table .

Image
 BMI category BMI Starvation <15 Anorexic 15.1 to 17.5 Under weight 17.6 to 18.5 Ideal 18.6 to 24.9 Over weight 25 to 25.8 Obese 30 to 30.9 Morbidly obese    >=40     #include<stdio.h> #include<conio.h> #include<math.h>  int main() { float weight ,height ,BMI; //Weight should be in kilograms // /Height should be in meter printf("Enter the weight of person:"); scanf("%f",&weight); printf("Enter the height of person:"); scanf("%f",&height); BMI=weight/pow(height,2); printf("The BMI of person is :%2f\n",BMI); if(BMI>0&&BMI<=15) printf("BMI category is starvation :"); else if(BMI>=15.1&&BMI<=17.5)  printf("BMI category is Anorexic: "); else if(BMI>17.6&&BMI<

re

* Write a C++ Program to design a class Temperature with two float variables fahren and celsius and a member function 'conversion' to convert fahrenheit into celsius */ #include using namespace std; // define a class Temperature class Temperature { private: float fahren, celsius; public: float conversion(float f) { fahren=f; celsius=(fahren-32)* 5.0/9.0; return celsius; } }; int main() { // define an object of Temperature class Temperature t; float f; cout<<"Enter Temperature in Fahrenheit="; cin>>f; // call conversion function with object t cout<<"Temperature in Celsius="<<t.conversion(f); return 0;

show the use of class in a c++

#include using namespace std; class person { char name[30]; int age; public: void getdata(void); void display(void); }; void persion:: getdata(void) { cout<<"Enter name:"; cin>>name; cout<<"Enter age:"; cin>>age; } void person ::display(void) { cout<<"\n name:"< code Copy

show the use of class in a c++

Image
show the use of class in a c++ #include<iostream> using namespace std;  class person  {  char name[30];   int age;  public:  void getdata(void);   void display(void);  };  void persion:: getdata(void)   {   cout<<"Enter name:";   cin>>name;  cout<<"Enter age:";  cin>>age;  }   void person ::display(void)  {  cout<<"\n name:"<<name; cout<<"\n age:<<age; } int main() { person p; p.getdata(); p. display(); return 0; } Copy code output-- Enter name :rajukumar Enter age:21 name:rajukumar age:21 related program--   Average of two number in c++ program

Average of two number in c++ program

Image
 Average of two number in c++ program #include<iostream> using namespace std; int main() {     float num1,num2,sum,average;     cout<<"\n"<<"enter first number:";     cin>>num1;     cout<<"\n"<<"enter second number:";     cin>>num2;     sum=num1+num2;     average=sum/2;     cout<<"sum="<<sum<<"\n";     cout<<"average="<<average<<"\n"; return 0;    } output --- Enter the first number:12  Enter the second number:21 sum=33 average=16.5     important program of c---    A certain grade of steel is graded according to following condition: (i) Hardness must be greater than 50. (ii)carbon content must be less than 0.7 (iii)Tensile strength must be greater than 5600. the grades as follows: grade is 10 if all three condition are met, Grade is 9 if conditions (i)and (ii) are met , Grade is 8 if condition (ii) and (iii) are met , Gra

A certain grade of steel is graded according to following condition: (i) Hardness must be greater than 50. (ii)carbon content must be less than 0.7 (iii)Tensile strength must be greater than 5600. the grades as follows: grade is 10 if all three condition are met, Gradeis 9 if conditions (i)and (ii) are met , Grade is 8 if condition (ii) and (iii) are met , Grade is 7 if condition (i) and (iii) are met, Grade is 6 if only one condition is met , Grade is 5 if none of the conditions are met . write a program which will require the user to give values of hardness , carbon content and tensile stength of the steel under consideration and output the grade of steel

Image
  A certain grade of steel is graded according to following condition:   (i) Hardness must be greater than 50.   (ii) carbon content must be less than 0.7   (iii)Tensile strength must be greater than 5600.    the grades as follows:  grade is 10 if all three condition are met,    Grade is 9 if conditions (i)and (ii) are met ,  Grade is 8 if condition (ii) and (iii) are met ,   Grade is 7 if condition (i) and (iii)  are met,    Grade is 6  if only one condition is met ,   Grade is 5 if none of the conditions are met .  write a program which will  require the user to give values of hardness , carbon content and tensile strength of the steel  under consideration and output the grade of steel #include<stdio.h> #include<conio.h>  int main() { //h=hardness  of steel // c= carbon content //ts=Tensile strength  float h,cc, ts; //flag for three condition int h_f =0,cc_f=0,ts_f=0; //is 0 represent fales  and one represent for true int grade; printf("Enter the value of hardness:&q

A digital world colors are specified in Red ,Green ,Blue(RGB) format with value of (R,G,b) varying on integers scale from 0 to 255 in point publishing the colors are mentioned in cyan, magenta - yellow black (CMYK) format ,with value of C,M,Y and k varying on real scale from 0.0 to 1.0 write the program to convert RGB colors to CMYK as per the following formula..White=max(Red/255,Green/255,Blue/255) ,cyan=(white-Red/255)/white , Magenta=(white -Green/255)/white , black = 1-white. note that if RGB value are 0 then the cmy values are all 0 and the k value is 1.

Image
A digital world colors are specified in Red ,Green ,Blue(RGB) format with value of (R,G,B) varying on integers scale from 0 to 255 in point publishing the colors are mentioned in cyan, magenta - yellow black (CMYK) format ,with value of C,M,Y and k varying on real scale from 0.0 to 1.0 write the program to convert RGB colors to CMYK as per the following formula.. White=max(Red/255,Green/255,Blue/255), cyan=(white-Red/255)/white  Magenta=(white -Green/255)/white  black = 1-white.   note that if RGB value are all 0 then the cmy values are all 0 and the k value is 1. #include<stdio.h> #include<conio.h> int main() { float r,g,b,rf, gf,bf, max,w,c,y ,m,k; printf(" Enter the value of red (0to 255):"); scanf("%f",&r); printf("Enter the value of green(0 to 255):"); scanf("%f",&g); printf("Enter the value of value of blue(0 to 255):"); scanf("%f",&b); rf=r/255; gf=g/255; bf=b/255; printf("Red:%f\n Gre