Skip to main content

The Fundamentals of Digital Marketing Certification

The Fundamentals of Digital Marketing Certification
Trying to make use of some spare time during these endless lockdowns. I completed The Fundamentals of Digital Marketing course on Google Digital Garage and got certified. This is not a great victory, nevertheless, I celebrate every small step towards a greater goal. #googlegarage #fundamentalsofdigitalmarketing #digitalmarketing

FDS 8

 Practical No: -8

Experiment No. 8: Write C++ program for storing binary number using doubly linked lists. Write

functionsa) To compute 1’s and 2’s complement.

b) Add two binary numbers.

Code:

#include<iostream>

using namespace std;

class binary;

class node

{

 node *prev;

 bool n;

 node*next;

public:

 node()

 {

 prev=next=NULL;

 }

 node(bool b)

 {

 n=b;

 prev=next=NULL;

 }

 friend class binary;

};

class binary

{

 node *start;


 public:

 binary()

 {

 start=NULL;

 }

 void generateBinary(int no);

 void displayBinary();

 void onesComplement();

 void twoscomplement();

 binary operator +(binary n1);


 bool addBitAtBegin(bool val)

 {

 node *nodee=new node(val);

 if(start==NULL)

 {

 start=nodee;

 }

 else

 {

 nodee->next=start;

 start->prev=nodee;

 start=nodee;

 }

 return true;

 }

};

void binary::generateBinary(int no)

{

 bool rem;

 node *p;

 rem=no%2;

 start=new node(rem);

 no=no/2;

 while(no!=0)

 {

 rem=no%2;

 no=no/2;


 /*

 if(start==NULL)

 {

 start=new node(rem);

 // cout<<" Start prev: "<<start->prev;

 // cout<<" Start next: "<<start->next ;


 }

 else

 {

 */

 p=new node(rem);

 p->next=start;

 start->prev=p;

 // cout<<" Start prev: "<<start->prev->n;

 // cout<<" p->n"<<p->n;

 start=p;


 //}

 }

}

void binary::displayBinary()

{

 node *t;

 t=start;

 while(t!=NULL)

 {

 cout<<t->n;

 t=t->next;

 }


}

void binary::onesComplement()

{

 node *t;

 t=start;


 while(t!=NULL)

 {

 if(t->n==0)

 t->n=1;

 else

 t->n=0;


 t=t->next;


 }

}

binary binary::operator +(binary n1)

{

 binary sum;

 node *a=start;

 node *b=n1.start;

// bit *s=sum.start;

 bool carry=false;

 while(a->next!=NULL)

 a=a->next;

 while(b->next!=NULL)

 b=b->next;


 while(a!=NULL && b!=NULL)

 {

 sum.addBitAtBegin((a->n)^(b->n)^carry);

 carry=((a->n&& b->n) || (a->n&& carry) || (b->n && carry));


 a=a->prev;

 b=b->prev;

 }

 while(a!=NULL)

 {

 sum.addBitAtBegin(a->n^carry);

 a=a->prev;

 }

 while(b!=NULL)

 {

 sum.addBitAtBegin(b->n^carry);

 b=b->prev;

 }

 sum.addBitAtBegin(carry);

 return sum;

}

void binary::twoscomplement()

{

 onesComplement();

 bool carry=1;

 node *t;

 t=start;

 while(t->next!=NULL)

 {

 t=t->next;

 }

 while(t!=NULL)

 {

 if(t->n==1&& carry==1)

 {

 t->n=0;

 carry=1;

 }

 else

 if(t->n==0&& carry==1)

 {

 t->n=1;

 carry=0;

 }

 else

 if(carry==0)

 break;


 t=t->prev;

}

displayBinary();

}

int main()

{

 int num,num1;

 binary n1,n3,n2;

 int choice=1;

 do

 {

 cout<<"\n\n=========Binary Number Operations========\n";

 cout<<"1. Generate binary\n2. One’s Complement\n3. Two’s

Complement\n4.Addition\n0.Exit\nEnter your choice: ";

 cin>>choice;

 switch(choice)

 {

 case 1: cout<<"\nEnter Number in decimal form: ";

 cin>>num;

 n1.generateBinary(num);

 cout<<"\nBinary Representation: ";

 n1.displayBinary();

 break;

 case 2:cout<<"\nEnter Number in decimal form: ";

 cin>>num;

 n1.generateBinary(num);

 cout<<"\nBinary Representation: ";

 n1.displayBinary();

 cout<<"\nOne's Complement: ";

 n1.onesComplement();

 n1.displayBinary();

 break;

 case 3:cout<<"\nEnter Number in decimal form: ";

 cin>>num;

 n1.generateBinary(num);

 cout<<"\nBinary Representation: ";

 n1.displayBinary();

 cout<<"\nTwo's complement: ";

 n1.twoscomplement();

 break;

 case 4: cout<<"\nEnter Two Numbers: ";

 cin>>num>>num1;

 n1.generateBinary(num);

 n2.generateBinary(num1);

 n1.displayBinary();

 cout<<" + ";

 n2.displayBinary();

 cout<<"= ";

 n3=n1+n2;

 n3.displayBinary();

 }

 }while(choice!=0);

 n1.generateBinary(7);

 cout<<"\nBinary Representation: ";

 n1.displayBinary();

//

// cout<<"\nOnes Complement: ";

// n1.displayBinary();

 cout<<"\nTwo's complement: ";

 n1.twoscomplement();

 return 0;




OUTPUT:


GALLERY

GALLERY
photos

ABOUT

HTML CSS, VB.net Developer and Java, C programming. With Loves Problem Solving and to Unreval the Mysteries behind the Magic of Computer Programming

Followers

MY PROJECTS

Popular posts from this blog

FDS 5

 Practical No: -5 Experiment No. 6: Write a python program to store first year percentage of students in array. Write function for sorting array of floating-point numbers in ascending order using a) Selection Sort b) Bubble sort and display top five score Code: # Function for Selection Sort of elements def Selection_Sort(marks):  for i in range(len(marks)):  # Find the minimum element in remaining unsorted array  min_idx = i  for j in range(i + 1, len(marks)):  if marks[min_idx] > marks[j]:  min_idx = j  # Swap the minimum element with the first element  marks[i], marks[min_idx] = marks[min_idx], marks[i]  print("Marks of students after performing Selection Sort on the list : ")  for i in range(len(marks)):  print(marks[i]) #<---------------------------------------------------------------------------------------> # Function for Bubble Sort of elements def Bubble_Sort(marks):  n = len(marks)  # Traverse throug...

FDS 4

 Practical No: -4 Experiment No. 4: a) Write a python program to store roll numbers of student in array who attended training program in random order. Write function for searching whether particular student attended training program or not, using linear search and sentinel search. b) Write a Python program to store roll numbers of student array who attended training program in sorted order. Write function for searching whether particular student attended training program or not, using Binary search and Fibonacci search. Code: import array as arr # Accept the Roll Numbers of the students def accept_roll():  a = arr.array('I', [])  no_stud = int(input("Enter the number of Students : "))  for i in range(0, no_stud):  a.append(int(input("Enter the Roll Number : ")))  return a # Print the Roll Numbers of the Students def print_roll(a):  for i in range(0, len(a)):  print("\t", a[i], end=" ")  print() # Linear Search def linear_search(a, x):  f...

Contact us

Name

Email *

Message *