Posts

FRIEND FUNCTION PROGRAM

Image
  CREATE TWO CLASSES dm AND db WHICH STORE THE VALUE OF DISTANCE. WRITE A PROGRAM THAT CAN READ VALUES FOR THE CLASS OBJECTS AND ADD ONE OBJECT OF dm WITH ANOTHER OBJECT OF db. USE A FRIEND FUNCTION TO CARRY OUT THE ADDITION OPERATION OBJECT THAT STORES THE RESULT MAY BE IN dm OBJECT OR db OBJECT DEPENDING ON THE UNITS ON WHICH THE RESULTS ARE REQUIRED. THE DISPLAY SHOULD BE IN THE FORMAT OF FEET AND INCHES OR METERS AND CENTIMETERS DEPENDING ON THE OBJECT ON DISPLAY. C++ PROGRAM: #include <iostream> #include <stdlib.h> using namespace std; // '& # 0 9 1 ;' is third left bracket class DB; class DM { float c1, c2, inc1; int m, cm, ft1; public: void m_cm(){ cout<<"M= "; cin>>m; cout<<endl<<"CM= "; cin>>cm; cout<<endl; } void convart1() { m=m*100; c1=m+cm; c2=c1*0.4; ft1=c2/12; inc1= c2-(ft1*12); } friend void add1(DM,DB); friend void add2(DM,DB); }; class DB

VECTOR

Image
  USING VECTOR CLASS Note: std::cout, std::cin, std::endl are used to resolve compilation error, you can use cout, cin, endl instead of that. #include <iostream> #include <vector> using namespace std; void display(vector<int> &v){ std::cout<<"Displaying the vector: "; for (int i=0;i< v.size();i++) { std::cout << v[i] <<" "; // std::cout << v.at(i) <<" "; } std::cout << "" << std::endl; } int main() { std::cout<<std::endl<<"\t\tZero length vector"<<std::endl; vector<int> vec1; int element,size=5; //cplusplus vector methods std::cout << "Enter the size of your vector: "; std::cin>>size; std::cout<<std::endl<<"\t\tpush_back in vector"<<std::endl; for(int i=0; i<size; i++) { std::cout << "Enter an element to add to the vector: "; std::cin>

MATRIX MULTIPLICATION

Image
  In this "MATRIX MULTIPLICATION PROGRAM" article, You can learn about matrix multiplication programs, matrix multiplication basics, dimensions, types of matrices, scalar multiplication, dot product, rule of multiplying matrices, algorithm, c and python program, and matrix multiplication program using python numpy. MATRIX MULTIPLICATION BASICS A matrix is a rectangular arrangement of numbers into rows and columns. it is also known as a 2-D array. Each cell contains a number and each number in a matrix is referred to as a matrix element or entry. The dimensions of the matrix tell its size: the number of rows and columns of the matrix, in that order. For example, MULTIPLYING MATRICES Since Matrix A has one row and three columns, so it's dimension is 1 × 3, pronounced as "1 by 3". Similarly, Matrix B has three rows and two columns, so its dimensions are 3 × 2. No of rows comes first then no of columns. (Dimension) Row is treated as

OPERATOR OVERLOADING

  PROGRAM 1: DEFINE A CLASS MAT OF SIZE M*N, DEFINE +, -, AND * OPERATOR OF MAT OBJECTS. WRITE A CPP PROGRAM TO TEST ABOVE CLASS FOR ABOVE OPERATIONS ON THE MAT OBJECTS. #include <iostream> #include <iomanip> class MAT { int m,n, mat[100][100]; public: void operator+(MAT); void operator-(MAT); void operator*(MAT); void getdata(); void display(); }; void MAT::getdata() { std::cout<<"Enter m: "; std::cin>>m; std::cout<<"Enter n: "; std::cin>>n; mat[m][n]; for(int i=0; i<m; i++) { for(int j=0; j<n;j++){ std::cout<<"Array["<<i<<"]["<<j<<"]: "; std::cin>>mat[i][j];} } } void MAT::display() { for(int i=0; i<m; i++) { for(int j=0; j<n; j++) { std::cout<<mat[i][j]<<" "; } std::cout<<std::endl; } std::cout<<std::endl; } void MAT::operator+(MAT m1) { if(m==m1.m && n==m1.n

CONSTRUCTOR & DESTRUCTOR

  WRITE A PROGRAM IN CLASS THAT CAN STORE AN INTEGER ARRAY OF DIFFERENT WITH FOLLOWING MEMBER FUNCTIONS A) CONSTRUCTOR WITH ARRAY SIZE =0 B) COPY CONSTRUCTOR C) DESTRUCTOR #include <iostream> class arr{ int a[100],size; public: arr(){ std::cout<<"CONSTRUCTOR INITIALIZED ARRAY SIZE TO 0"; size=0; a[size]; } arr(arr &x); ~arr() { std::cout<<std::endl<<"DESTRUCTOR INVOLVED ~~ FREE MEMORY"; } }; arr::arr(arr &x) { std::cout<<std::endl<<"COPY CONSTRUCTOR INVOLVED"; size=x.size; a[size]; for(int i=0; i<x.size; i++) { a[i]=x.a[i]; } } int main() { arr a1; arr a2(a1); } INPUT-OUTPUT: CONSTRUCTOR INITIALIZED ARRAY SIZE TO 0 COPY CONSTRUCTOR INVOLVED DESTRUCTOR INVOLVED ~~ FREE MEMORY DESTRUCTOR INVOLVED ~~ FREE MEMORY This article is updated every month. Bookmark this for more interesting posts.

C PROGRAMMING NOTE

Image
  In this " C PROGRAMMING NOTE 1 ", You can learn header files in c like stdio.h [ printf(), scanf(), getc(), putc(), fopen(), fclose(), remove(), flush() ], stdlib.h [ malloc(), free(), abort(), exit(), atol(), atoll(), atof(), rand() ], sys/types.h [ block, key, pthread, time, trace, uid ], sys/stat.h [ fstat(), lstat(), stat(), mode, link, id, time,st_mode file type, file mode bits ], dirent.h [ opendir, readdir, telldir, seekdir, rewinddir, or closedir subroutine ], and components of command line arguments , exit , return , return type topics. If you are a beginner then it will help you in your exams, and even competitive exams. This C PROGRAMMING NOTE 1, covers C Statements and what is the functionality of it, is discussed in short. HEADER FILES   HEADER FILE WITH DESCRIPTION #include<stdio.h> The header file "stdio.h" is written as #include<stdio.h>. The # include preprocessor directive is used to paste the code of a