c++

facts about c++

Constructor constructor is a special type of function or method in which there is No return type(Even void) and constructor name will be same as the name of the class. There are two types of constructor1.default constructor2.parameterised constructor Passing Objects as Function Arguments in C++class Test{public : /*here we are passing Test the name of …

facts about c++ Read More »

c++ to display the values we are passing from parameterised constructor.

//To display the values of parameterised constructor.#include<iostream>using namespace std; class add{ int num1,num2,sum; public : add(int x,int y); void display();};add::add(int x,int y) { num1=x; num2=y; sum=x+y; }void add::display() { cout<<“The nummbers are “<<num1<<“t”<<num2<<“n”; }int main()  {  add b=add(10,20);  b.display();  } OUT-The numbers are 10 20

write a c++ program to find odd numbers in range.

Source code- #include<iostream> using namespace std; int main(){ int min,max,num; cout<<“Enter minimum range “; cin>>min; cout<<“Enter maximum range “; cin>>max; for(num=min;num<=max;num++) if(num%2!=0) cout<<num<<“t”; } OUTPUT- Enter minimum range 1 Enter maximum range 10 1 3 5 7 9

Program name:-write a c++ program to convert celsius to fahrenheit and vice versa.

Sourcee code – #include<iostream> using namespace std; float celsius_To_Fahrenheit(float celsius); float fahrenheit_To_celsius(float fahrenheit); int main(){ float celsius,fahrenheit,celsi,entered_fahrenheit; cout<<“Enter celcius to convert to fahrenheit “; cin>>celsius; fahrenheit=celsius_To_Fahrenheit(celsius); cout<<fahrenheit; cout<<“nEnter fahrenheit to convert to celsius “; cin>>entered_fahrenheit; celsi=fahrenheit_To_celsius(fahrenheit); cout<<celsi; } float celsius_To_Fahrenheit(float celsius){ float fahrenheit; //T(°F) = 20°C × 9/5 + 32 = 68 °F fahrenheit=((celsius*9)/5)+32; return fahrenheit; } float fahrenheit_To_celsius(float entered_fahrenheit){ float celsi; //T(°C) = (68°F – 32) × 5/9 = 20 °C celsi=((entered_fahrenheit-32)*5)/9; return celsi; } OUTPUT- Enter celcius to convert to fahrenheit 20 68 Enter fahrenheit to convert to celsius 68 20

c++ program to print Average of a batsman using classes and objects.

/*write a c++ program to define a class batsman with the following informationprivate variablebcode 4 digit,bname 20 char,innings,notout,bat avg(float)which calculated(runs/(innings-notout))byfunction calc_avgpublic member :readdata() to accept values ofbcode,bname,innings,notout,runs and invoke calc_avg to calculate the avg.display() to display*/#include<iostream>using namespace std; class Batsman{ int bcode,innings,notout,runs; float bat_avg; char bname[20]; float calc_avg()    { bat_avg =(float) runs/((float) innings -(float)notout); …

c++ program to print Average of a batsman using classes and objects. Read More »

c++ program for fibonacci using recursion

#include<iostream>using namespace std;long fact(int num);int main(){ int num; cout<<“Enter number for factorial “; cin>> num; cout<<“Factorial of “<< num <<endl<<fact(num); } long fact(int num) { if(num==0) return 1; else { return (num*fact(num-1)); }} OUTPUT- Enter number for factorial 5 Factorial of 5 120

c++ creating class person with two private variable name and age and two public functions

//create class person with two private variable name and age and two public fn void get data and void put data #include<iostream>using namespace std;class person{ char name[50]; int age; public: void getdata(); void putdata();}; void person::getdata(){ cout<<“Enter the name : “; cin>>name; cout<<“Enter the age”; cin>>age;} void person::putdata(){ cout<<“Name : “<<name; cout<<endl<<“age : “<<age;} int …

c++ creating class person with two private variable name and age and two public functions Read More »

c++ program to create an item with two private num int and float cost with two public functions

/*WAP to create a class item with two private variable number -int cost -float  and two public function void getdata() and void putdata() */ #include<iostream>#include<stdio.h>using namespace std;class item{ int number; float cost; public: void getdata(); void putdata();}; void item::getdata(){ cout<<“Enter the number : “; cin>>number; cout<<“Enter the cost”; cin>>cost;} void item::putdata(){ cout<<“Number : “<<number; cout<<endl<<“Cost : “<<cost;} int …

c++ program to create an item with two private num int and float cost with two public functions Read More »

Open chat