Posts

Square root Algorithm in C++

 Here is the way you can find the square root of any number by writing your own code in c++.  #include<iostream> using namespace std; double sqrt(double num){ double stop_condition = 0.00000001; double guess = num/2; while((guess-num/guess) > stop_condition){ guess = (guess+num/2)/2; } return guess; } int main(){ double num = 4; cout<<"The result is: "<<sqrt(num)<<endl; return 0; }

OOP lab 7 task solution

  #include <iostream> using namespace std ; class position { public: int x ; int y ; position (){ x = 0 ; y = 0 ; } position operator + ( position & p_any ){ position p1 ; p1 . x = this -> x + p_any . x ; p1 . y = this -> y + p_any . y ; return p1 ; } }; int main (){ position p1 ; cout<< "Enter the intial values of x and y cordinates: " ; cin>> p1 . x >> p1 . y ; position p2 ; cout<< "Enter the new values for x and y to be shifted: " ; cin>> p2 . x >> p2 . y ; position p3 ; p3 = p1 + p2 ; cout<< "The initial values were: " << p1 . x << " " << p1 . y <<endl; cout<< "The new values are: " << p3 . x << " " << p3 . y <<endl; } // from now onward this is the second task #in...

OOP Assignment 3 helping materials

 Following is the code that will help you in the assignment for the addition of the arrays using operator overloading and returning an object. #include<iostream> using namespace std; int num; struct add {     int ar[20]; }; add operator+(add &a1,add &a2) {     add a3;     for(int i=0;i<num;i++)         a3.ar[i]=a2.ar[i]+a1.ar[i];     return a3; } int main() {     add a1,a2,a3;     cout<<"How many elements to be stored (max 20) : ";     cin>>num;     cout<<"Enter elements of array a1 : ";     for(int i=0;i<num;i++)         cin>>a1.ar[i];     cout<<"Enter elements of array a2 : ";     for(int i=0;i<num;i++)         cin>>a2.ar[i];     a3=a1+a2;     cout<<"Addition of two arrays : ";     for(int i=0;i<num;i++)   ...

Keeping Home Routers secure while working remotely

  KEEPING HOME ROUTERS SECURE WHILE WORKING REMOTELY Many employees are working remotely due to the pandemic, so security teams are facing a new challenge of how to secure everyone's home routers as they may be vulnerable to attacks. Home routers are a more static and predictable location for an attacker, especially if we are including Wi-Fi access points, common to all-in-one gateway devices. Home routers also include a variety of entertainment and home automation devices, all of which could have their own vulnerabilities. The easiest and most efficient method to tackle this issue is to provide every company employee with some basic security education. The below given guidelines can be followed to increase router security and prevent unexpected attacks: Log in to your router, check for firmware updates, and upgrade if one is available. Set up a monthly task as a reminder to log in to see whether any new versions are available. Verify that "Remote Administration" or ...

C++ Abstract classes and pure virtual functions

  /* * Abstract class: A class which does not contain implementation. * * abstract class must have at least one pure virtual function. * * Pure virtual function: It does not have body. * Syntax: * virtual void function_name(argument_list) = 0; * * C++ is supporting pure virtual destructor as well. However, this * is different from pure virtual function. Because, pure virtual * de s tructor must have function body. * */ #include <iostream> using namespace std; class Animal { public: virtual void run() = 0 ; virtual void speak() = 0 ; // virtual destructor is recommended if there is any // virtual function in a class virtual ~ Animal() { } }; class Dog : public Animal { public: virtual void speak() { cout << "Woof!" << endl; } }; class Labrador : public Dog { public: Labrador() { cout << "New Labrador" << endl; } virtual void run() { cout <...

Concept of Signed and Unsigned Numbers

Image
  Core concepts of Signed Binary Numbers  And Explanation of Ranges of Different Datatypes. If I would ask what is the value of (1000 0000) 2  in decimal then certainly two ambiguous answers will come up (-128) 10  and (+128) 10  . The answer is really ambiguous as both answers are correct. So the concept of signed and unsigned numbers comes up to help overcome the ambiguity. Now if it is given to be unsigned number the  (+128) 10  is the correct answer because there is no sign bit in case of unsigned numbers. Thus, here the MSB(Most Significant Bit ) is not reserved to represent sign of number. But in case it is given that it is signed number, the  (-128) 10   is the correct answer. In case of signed numbers the MSB is reserved to represent the sign of the number. Thus if the number is of n bits, then in this 1 bit is used for representing sign of the number and rest (n-1) bits are used to represent the magnitude of the number. Methods ...

C++: Program to format Date And Time structure

Image
   Format Date and Time in C++ Introduction: The  tm  structure is very important while working with date and time in either C or C++. This structure holds the date and time in the form of a C structure as mentioned above. Most of the time-related functions make use of tm structure. Following is an example which makes use of various date and time-related functions and tm structure : While using structure in this chapter, I'm making an assumption that you have basic understanding on C structure and how to access structure members using arrow -> operator. Program to Format Date and Time in C++ : OUTPUT: That's it for this blog. Hope you learned something new today :)