Posts

C++ OBJECT ORIENTED PROGRAMMING PART-2

Image
  Object : Object means real word entity such as pen, chair, table etc Any entity that has a state and behaviour is known as an object. It can be physical and logical.  Object is an instance of class.  Example :- Car is an object. Its name is mercedes. Its colour is black etc known as its state. It is used for driving so driving is its behaviour.  An object has three characteristics: State:-Represent the data of an object Behaviour:-Represent the functionality of an object.  Identity :-object identity is typically implemented via unique ID. The value of the ID is not visible to external user. But it is used internally by  the JVM to identify each object uniquely.  Syntax to Define Object in C++ className objectVariableName; Example of object that maintains the record of students: Output: Explanation : In above example class that has 2 fields ID and name. It creates instance of the class, Initializes the object and print the object value.

C++ Object oriented programming Part-1

Image
  OOP stands for Object-Oriented Programming .  Defination:   Object oriented programming is a methodology to design program using classes and objects. The building blocks of object Oriented Programming Concept: It simplifies the software development and maintenance by using this concept: Object  Class Polymorphism  Encapsulation  Inheritance  Abstraction Procedural programming is about writing procedures or functions that perform operations on the data, while object-oriented programming is about creating objects that contain both data and functions . Advantages of Object oriented programming over procedural programming: Object oriented programming makes development and maintenance easier where as in procedural programming it is not easy to manage if code grows as project size grows.  Object oriented programming providing data hiding  where as in procedural programming a global data can be accessed from anywhere.  Object oriented program...

What is the difference between Coder, Programmer& Developer, Software engineer?

Image
  HOW DO YOU DIFFERENTIATE BETWEEN THESE TERMS AND KNOW WHAT DO THEY ALL MEAN AND WHO DO YOU TURN TO WHEN YOU JUST NEED TO GET SOMETHING DONE? In reality, these terms are often used interchangeably, that vary from organization to organization, and can even mean different things depending on the circumstance.                   Coders One who can write some code is often referred to as a coder by the people outside of the tech industry. But, usually, coders are considered the least trained or experienced level of programmers. These individuals do not have the same algorithmic knowledge as a programmer or developer, as they are often a beginner in the field, skilled in just one coding language. We can also say that a nyone who can write some code that compiles and runs, which will do something they want when its given the right inputs. This could be a program, a script, some classes or a library. Programmers They are more experienced coders...

OPERATOR OVERLOADING

  Operator overloading  is a compile-time polymorphism in which the  operator  is  overloaded  to provide the special meaning to the user-defined data type. Operators which cannot be overloaded: 1.Scope Resolution Operator 2.Conditional Operator 3. Class Access Operator 4. Size Of Operator It can be done either by friend function or member function: The difference is: Member function takes One argument for binary operator and none for unary operator whereas Member takes two for binary and one for unary operators Program Code: # include <iostream> using namespace std ; class integer { int no; public : void input () { cout << "Enter Number" ; cin >>no; } void display () { cout << "Number is " <<no<< endl ; } void operator -() { no=-no; } }; int main () { integer o; o.input(); o.display(); -o; // unary minu...

OOP Assignment 2

  #include <iostream> #include <fstream> using namespace std ; struct student { char regno [ 9 ]; float gpa ; char name [ 10 ]; }; int main (){ ifstream datastream ( "studentsdata.txt" ); if ( ! datastream ) { cerr << "Error opening file" << endl ; exit (- 1 ); } int num = 0 ; datastream >> num ; // allocate memory for num student objects student * p = new student [ num ]; if ( p == NULL ) { cerr << "Error allocating memory" << endl ; exit (- 1 ); } for ( int i = 0 ; i < num ; i ++){ datastream >> p [ i ]. regno >> p [ i ]. gpa >> p [ i ]. name ; } int beststudent = 0 ; float bestgpa = 0.0 ; for ( int i = 0 ; i < num ; i ++){ if ( p [ i ]. gpa > bestgpa ){ bestgpa = p [ i ]. gpa ; beststudent = i ; } } cout << "The best student of class is:" << endl ...

EULER Q2 Solution

  #include <iostream> using namespace std ; int LargestPrime ( int ); int LargestPrime ( int TheNum ) { int FactorCount = 0 ; for ( int i=TheNum; i>= 2 ; --i) { for ( int j= 2 ; j<i; ++j) { if (i % j == 0 ) { ++FactorCount; } } if (FactorCount == 0 ) { return i; break ; } FactorCount = 0 ; } return 0 ; } int main () { int Input, Result; cout << "Enter the number: " ; cin >> Input; Result = LargestPrime (Input); cout << "The largest prime number before " << Input << " is " << Result << endl; return 0 ; }

EULER Q1 Solution

  #include <iostream> using namespace std ; int fib ( int x ) { if ((x== 1 )||(x== 0 )) { return (x); } else { return ( fib (x- 1 )+ fib (x- 1 )); } } int main () { int x , i= 0 ; cout << "Enter the number of terms of series : " ; cin >> x; cout << " \n Fibonnaci Series : " ; while (i < x) { cout << " " << fib (i); i++; } cout<<endl; return 0 ; }