Back to Top

Dynamic Memory Allocation এবং FILE Operation and Pointer in C Program


Call by Value এবং Call by Reference ব্যাখ্যা কর ।

Call By ValueCall By Reference

Original Value এর কোনো পরিবর্তন হয় না।

এখানে Original Value এর পরিবর্তন হয় ।

এখানে ভেরিয়েবলের অনুলিপি (Copy of variable) পাস হয়ে থাকে। 

এখানে ভেরিয়েবল নিজেই পাস হয়ে থাকে।

Actual এবং Formal Argument ভিন্ন ভিন্ন Memory Location এ তৈরি হয় । 

Actual এবং Formal Argument একই Memory

Location এ তৈরি হয়। 

ভেরিয়েবলের মান কে একটি সরল পদ্ধতি ব্যবহার করে পাস করা হয়

ভেরিয়েবলের ঠিকানা (Address of Variable)সঞ্চয় করতে পয়েন্টার এর প্রয়োজন হয় ।

int main() {

     int x = 10;
     printf("before calling=%d",x);
      increment(x);
     printf("After calling=%d",x);
     getch();
   }
    void increment(int a) {
                 a = a + 1;
                printf("value is=%d",a);
     }

 int main() {

      int x = 10;
      printf("before calling=%d",x);
      increment(&x);
      printf("After calling=%d",x);
      getch();
    }
    void increment(int *a) {
                 *a = *a + 1;
                printf("value is=%d",*a);
     }

Digital Electronics

Sequential Logic Circuit

What is Sequential Logic Circuit (সিকোয়েন্সিয়াল লজিক সার্কিট কি)?

The sequential Logic Circuit has a memory so output depends on the input. Sequential Logic Circuits use flip-flops as memory elements.

[সিকোয়েন্সিয়াল লজিক সার্কিটের মেমরি রয়েছে তাই আউটপুট ইনপুটের উপর নির্ভর করে। সিকোয়েন্সিয়াল লজিক সার্কিট মেমরি উপাদান হিসাবে ফ্লিপ ফ্লপ ব্যবহার করে ।] 

Flip Flop vs Latch

What is Flip Flop (Flip flop কাকে বলে )?

A flip flop is an electronic circuit which two states. A flip flop is used to store 1-bit binary data. [ফ্লিপ ফ্লপ  হল একটি electronic circuit যার দুটি অবস্থা বর্তমান । একটি ফ্লিপ ফ্লপ 1 বিট বাইনারি তথ্য সঞ্চয় করতে ব্যবহৃত হয় । 

What is Latch (Latch কাকে বলে )?

The latch is also an electronics device that has two states and used to store 1-bit binary data. Latch has no clock connection and it is level triggered.[Latch  ও flip flop এর ন্যায় একটি electronic circuit যার দুটি অবস্থা বর্তমান ।Latch  ও 1 বিট বাইনারি তথ্য সঞ্চয় করতে ব্যবহৃত হয় কিন্তু ল্যাচ(Latch) ফ্লিপ ফ্লপ (Flip flop)এর ন্যায় কোন  clock signal প্রদান করা হয় না  এবং ইহা clock pulse এর Level Triggered এ কাজ করে। নিম্নলিখিত ভিডিও তে আর ও বিস্তারিত আলোচনা করা হয়েছে।   ]                                           
  

S-R FlipFlop কাকে বলে ? 

নিম্নলিখিত ভিডিও র মাধ্যমে  S-R flip flop সম্পূর্ণ ব্যাখা দেওয়া হয়েছে।


 D(Data or Delay)-FlipFlop 

নিম্নলিখিত ভিডিও র মাধ্যমে  D flip flop এর সম্পূর্ণ ব্যাখা দেওয়া হয়েছে। D flip flop কে কেন data বা   delay ফ্লিপফ্লপ বলা হয়ে থাকে সে বিষয়ে ও আলোকপাত করা হয়েছে।




J-K-FlipFlop 

নিম্নলিখিত ভিডিও র মাধ্যমে  J-K flip flop এর সম্পূর্ণ ব্যাখা দেওয়া হয়েছে। 



Register, Clock Pulse, and Trigger 

নিম্নলিখিত ভিডিও র মাধ্যমে Register,Clock Pulse and Trigger  এর সম্পূর্ণ ব্যাখা দেওয়া হয়েছে।


নিম্নলিখিত ভিডিও র মাধ্যমে গুরুত্বপূর্ন কয়েকটি Register -এর সম্পূর্ণ ব্যাখা দেওয়া হয়েছে। 






Counter In Digital Electronics: Asynchronous Counter




 








Object Oriented Programming

Year Basis Question and Answer Of  C++ 

[2015]

1) Do the Following Task using C++ language in OOP

a) Design a Class having Name Circle
b) Declare an integer data for taking value of radius of that circle and take that input through get input() function
c) Find out the area of circle using another member function 

Answer

#include<iostream>
using namespace std;
class circle{
public :
int r;
float area;
void input(){
cout<<"Enter radious of circle:";
cin>>r;
}
void findArea(){
                              area=3.14*r*r;
}
void display(){
   cout<<"Area of circle is:";
   cout<<area;
}
};
int main(){
circle obj;
obj.input();
obj.findArea();
obj.display();
}

[2016]

a) Write a program in C++ that accepts two number as input and find the sum using class and object

Answer:

#include<iostream>

using namespace std;

class Sum_Two_Num{

public :

int a,b,sum;

void inputNumber(){

cout<<"Enter Two Number :";

cin>>a>>b;

}

void findSum() {

sum=a+b;

}

void display() {

   cout<<"Sum of two number is:";

   cout<<sum;

}

};

int main(){

Sum_Two_Num obj;

obj.inputNumber();

obj.findSum();

obj.display();

}

b) What is Polymorphism? Explain with example

Answer:

polymorphism is an important concept of object-oriented programming.it means having many forms. Inheritance lets us inherit attributes and methods from another class. Polymorphism uses those methods to perform different tasks. This allows us to perform a single action in different ways.

Example:

class MotorBike {

  public:

    void speed() {

    cout << "This is Hero's speed \n" ;

  }

};

// Derived class

class Honda : public MotorBike {

  public:

    void speed() {

    cout << "This is Honda's speed \n" ;

  }

};

// Derived class

class Enfield : public MotorBike {

  public:

    void speed() {

    cout << "This is Enfield's speed\n" ;

  }

};



[2017]

a) Write a program in C++ to check an integer whether it is odd or even using class and object?

Answer:

#include<iostream>

using namespace std;

class Odd_Even {

    int num;

public:

    void input() {

        cout << "Enter a number:";

        cin>>num;

    }

    void Check_OddEven() {

        if (num % 2 == 0) {

            cout << "Number is even:" << num;

        } else {

            cout << "Number is odd:" << num;

        }

    }

};

int main() {

    Odd_Even obj;

     obj.input();

     obj.Check_OddEven();

     return 0;

}

b) What do you mean by Data Member? Give example?

Data Members are variable which are declared in any class by using any fundamental data types

 (like int, char, float etc) or derived data type (like class, structure, pointer etc.).

There are two types of data member

 1) Private  2) Public 

Example: 

class DataMember {

        private:

                int x;

                float a;

        public:

                 int m;

                float n;

};

OR

a) Give the difference between public and private member of the class in C++

Answer:

Public Private

1. All the class members and functions are available to everyone.

1.The class members can be accessed only by the functions inside the class.

2. The public member can be accessed from anywhere in the program using the dot operator(.)with the object
of that class.

2.the member functions or the friend functions are allowed to access the private data members of a class

Example:
class Subtraction { 
public:
        int a,b;
        int calculate(){
            return (a-b);
     }
};
int main(){
      Substraction obj;
      // accessing public data member outside class
      obj.a=20;
      obj.b=10;
      cout<<"Substraction is: " << obj.calculate();
      return 0;
}

Example:
class Subtraction {
     private:
              int a,b;
     private:
              void calculate(int x,int y){
                a=x;
                b=x;
                int result=a-b;
                cout<<"Substraction is="<<result;
            }
};
int main(){
            Substration obj;
            obj.calculate(20,10);
            return 0;
}


b) Describe the characteristic of destructor in C++

Answer:

  • The destructor has the same name as that of the class prefixed by the tilde character ‘~’.

  • The destructor cannot have parameters.

  • It has no return type

  • there can be only one destructor in a class

  • The destructor is executed automatically when the control reaches the end of the class scope to destroy the object


c) What do you mean by "get from" Operator in C++? Give example?

Ans: Extraction Operator (>>) sometimes known as "get from" operator which is usually used for input data from the user.

[2018]

a) Write a program in C++ using class and object to check an integer whether is a prime number or not.

Answer:

using namespace std;  

int main()  

{  

  int n, i,check=0;  

  cout << "Enter the Number to check Prime: ";  

  cin >> n;  

  for(i = 2; i <=n/2; i++)    {  

      if(n % i == 0)  

      {  

          cout<<"Number is not Prime."<<endl;  

          check=1;  

          break;  

      }  

  }  

  if (Check==1)  {

      cout << "Number is Prime."<<endl;  

  return 0;  

}  

b) What is the member function? Give example?

A member function of a class is a function that has its definition or its prototype within or outside the class. member function knows as a method also.

There are two way to define a function

  1) inside the class-defined directly

  2) outside of the class- using scope resolution operator(::) along with class name

Example: 

// Member functions defined within class

class Circle {

   public:

      double r=2.5;         // variable

      double getArea(void) {

        return 3.14*r*r;

      }};

//OR Member functions defined outside of the class

class Circle {

   public:

      double r=2.5;         // variable        

};

class Circle::double getArea(void)    {

        return 3.14*r*r;

      }

int main(){

     Circle obj;

     cout<<"Area of Circle:"<<obj.double getArea();

}

OR

a) Write a program in C++ to find out the factorial of a given integer (N!= 1x2x3x........N)

Answer:

using namespace std;

class FindFactorial {

public:

    int factorial(int N) {

        int i, f = 1;

        for (i = 1; i <= N; i++) {

            f = f*i;

        }

        return f;

    }

};

int main() {


    FindFactorial obj;

    int N;

    cout << "Enter a number:";

    cin >> N;

    cout << "Factorial is:" << obj.factorial(N);

    return 0;

}

b) How a member function can be declared outside of the class? Give example?

Anwser:

A member function can be declared outside of the class using the scope resolution operator (::) along with the class name.

Example:

class Circle {

   public:

      double r=2.5;         // variable        

};

class Circle::double getArea(void)    {

        return 3.14*r*r;

      }

int main(){

     Circle obj;

     cout<<"Area of Circle:"<<obj.double getArea();

}

[2019]

a) Write a program in C++ using class and object to find out the sum 1 to N where N is an integer given as input.

Answer:

#include<iostream>
using namespace std;
class Sum_Of_N_Num{
public :
int N,i,sum=0;
void inputNumber(){
cout<<"Enter Number :";
cin>>N;
}
void findSum()
{
for(i=0; i<=N; i++){
sum=sum+i;
}
}
void display()
{
   cout<<"Sum of N number is:";
   cout<<sum;
}
};
int main(){
Sum_Of_N_Num obj;
obj.inputNumber();
obj.findSum();
obj.display();
}

b)Write a function of setw and endl manipulator.

Answer:

endl

 This manipulator has the same functionality as ‘\n’(newline character). But this also flushes the output stream.

setw()

 This manipulator declare in imanip.h . it changes the width of the output field. When used in an expression out << setw(n)output field.

Example:

#include<iostream>

#include<iomanip>

using namespace std;

int main(){

            cout<<"USING setw() ..............\n";

    cout<< setw(10) <<11<<endl;

    cout<< setw(10) <<2222<<endl;

    cout<< setw(10) <<33333<<endl;

    cout<< setw(10) <<4<<endl;

}

OR

a) Write a program in C++ to print the reverse of given number.

Answer:

#include <iostream>

using namespace std;

int main() {

    int num, revNum = 0, rem;


    cout << "Enter an integer: ";

    cin >> num;

    while(num!= 0) {

        rem = num%10;

        num /= 10;

        revNum = revNum*10 + rem;     

    }

    cout << "Reversed Number = " << revNum;

    return 0;

}


b) what do you mean by reference variable? Give example?

Answer:

When a variable is declared as a reference, it becomes an alternative name for an existing variable. A variable can be declared as a reference by putting '&' in the declaration.

Example:

#include<iostream>

using namespace std;

int main(){

int x=10;

int& ref=x;

//value of x is now changed

ref=20;

cout<<"x="<<x<<endl;

//value of ref is now changed

x=30;

cout<<"ref="<<ref<<endl;

return 0;

}

Important Question Based on Computer Application -XI



    

Single Link List using C program with algorithm

Algorithm 



InsertNodeAtBegining()

                    If (newNode == NULL) then
                        print ('Unable to allocate memory')
                    End if
                    Else then
                            read item
                            newNode.item ← item
                            newNode.next ← head
                            head ← newNode
                    End else

InsertNodeAtEnding()

                     If (newNode == NULL) then
                            print ('Unable to allocate memory')
                    End if
                    Else then
                            read item
                            newNode.item ← item
                            newNode.next ← NULL
                            temp ← End
                            While (temp.next != NULL) do
                            temp ← temp.next
                            End while
                            temp.next ← newNode
                    End else

InsertNodeAtMiddle()

                                 If (newNode == NULL) then
                                        write ('Unable to allocate memory.')
                                 End if
                                Else then
                                        read item
                                        newNode.item ← item
                                        temp ← head
                                            For i ← 2 to n-1
                                                temp ← temp.next
                                                    If (temp == NULL) then
                                                        break
                                                    End if
                                            End for
                                        If (temp != NULL) then
                                            newNode.next ← temp.next
                                            temp.next ← newNode
                                            End if
                                End else

deleteFirstNode()

                                  If (head==NULL)
                                                print “List Empty”
                                  end if
                                   else
                                         temp = head
                                         head = head.next
                                        delete temp
                                   End

deleteLastNode() 

                                     If (head == NULL) then
                                               print ('List is already empty')
                                     End if
                                     Else then
                                                temp ← head
                                                previousNode ← head
                                     While (temp.next != NULL) do
                                                previousNode ← temp
                                                temp ← temp.next
                                     End while
                                    If (temp == head) then
                                            head ← NULL
                                    End if
                                        Else then
                                                previousNode.next ← NULL
                                        End else
                                                free (temp)
                                    End

deleteMiddleNode()

                                    If (head == NULL) then
                                                print('List empty')
                                    End if
                                    Else then
                                                temp ← head
                                                 previousNode ← head
                                    For i←2 to n do
                                                previousNode ← temp
                                                temp ← temp.next
                                        If (temp == NULL) then
                                                break
                                        End if
                                    End for
                                    If (temp != NULL and temp == head) then
                                                   head ← head.next
                                    End if
                                    Else
                                                    previousNode.next ← temp.next
                                                    temp.next ← NULL
                                                    free (temp)
                                     End else
                                     End

Source Code of Single Link List operation

/*
Single Link List using C program
*/

#include <stdio.h>
#include <stdlib.h>

/* Structure of a node */
struct node
{
int item;
struct node *next;
} * head;

void createList(int n);
void displayList();
void insertNodeAtBeginning(int item);
void insertNodeAtEnd(int item);
void insertNodeAtMiddle(int item, int position);
void deleteFirstNode();
void deleteLastNode();
void deleteMiddleNode(int position);
int main()
{
int n, item, position;
int choice;
for (;;)
{
printf("\n===========::Single Link List Menu::=================\n\n ");
printf("\n1. Press 1 for Creating Lists\n");
printf("\n2. Press 2 for display Lists\n");
printf("\n3. Press 3 for insert item into fisrt Position of Lists\n");
printf("\n4. Press 4 for insert item into last Position of Lists\n");
printf("\n5. Press 5 for insert item into specified middle Position of Lists\n");
printf("\n6. Press 6 for delete item from fisrt Position of Lists\n");
printf("\n7. Press 7 for delete item from last Position of Lists\n");
printf("\n8. Press 8 for delete item from specified middle Position of Lists\n");
printf("\n===========::Single Link List Menu::=================\n ");
printf("\n\tEnter your choice:");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("Enter the total number of nodes: ");
scanf("%d", &n);
createList(n);
break;
case 2:
printf("\nitem in the list \n");
displayList();
break;
case 3:
printf("\nEnter item to insert at beginning of the list: ");
scanf("%d", &item);
insertNodeAtBeginning(item);
break;
case 4:
printf("\nEnter item to insert at end of the list: ");
scanf("%d", &item);
insertNodeAtEnd(item);
break;
case 5:
printf("nEnter item to insert at middle of the list: ");
scanf("%d", &item);
printf("Enter the position to insert new node: ");
scanf("%d", &position);
insertNodeAtMiddle(item, position);
break;
case 6:
deleteFirstNode();
break;
case 7:
deleteLastNode();
break;
case 8:
printf("\nEnter the node position you want to delete: ");
scanf("%d", &position);
deleteMiddleNode(position);
break;
case 9:
exit(1);
break;
default:
printf("Wrong selction");
}
}
return 0;
}

void createList(int n)
{
struct node *newNode, *temp;
int item, i;

head = (struct node *)malloc(sizeof(struct node));

if (head == NULL)
{
printf("Unable to allocate memory.");
exit(0);
}

printf("Enter the item of node 1: ");
scanf("%d", &item);

head->item = item;
head->next = NULL;

temp = head;
for (i = 2; i <= n; i++)
{
newNode = (struct node *)malloc(sizeof(struct node));

if (newNode == NULL)
{
printf("Unable to allocate memory.");
break;
}

printf("Enter the item of node %d: ", i);
scanf("%d", &item);

newNode->item = item;
newNode->next = NULL;
temp->next = newNode;
temp = temp->next;
}
}
void displayList()
{
struct node *temp;

if (head == NULL)
{
printf("List is empty.");
}
else
{
temp = head;
while (temp != NULL)
{
printf("item = %d\n", temp->item);
temp = temp->next;
}
}
}
void insertNodeAtBeginning(int item)
{
struct node *newNode;

newNode = (struct node *)malloc(sizeof(struct node));

if (newNode == NULL)
{
printf("Unable to allocate memory.");
}
else
{
newNode->item = item;
newNode->next = head;

head = newNode;

printf("item INSERTED SUCCESSFULLY\n");
}
}
void insertNodeAtEnd(int item)
{
struct node *newNode, *temp;

newNode = (struct node *)malloc(sizeof(struct node));

if (newNode == NULL)
{
printf("Unable to allocate memory.");
}
else
{
newNode->item = item;
newNode->next = NULL;

temp = head;

while (temp != NULL && temp->next != NULL)
temp = temp->next;

temp->next = newNode;

printf("item INSERTED SUCCESSFULLY\n");
}
}
void insertNodeAtMiddle(int item, int position)
{
int i;
struct node *newNode, *temp;

newNode = (struct node *)malloc(sizeof(struct node));

if (newNode == NULL)
{
printf("Unable to allocate memory.");
}
else
{
newNode->item = item;
newNode->next = NULL;

temp = head;

for (i = 2; i <= position - 1; i++)
{
temp = temp->next;

if (temp == NULL)
break;
}

if (temp != NULL)
{

newNode->next = temp->next;

temp->next = newNode;

printf("item INSERTED SUCCESSFULLY\n");
}
else
{
printf("UNABLE TO INSERT item AT THE GIVEN POSITION\n");
}
}
}
void deleteFirstNode()
{
struct node *toDelete;

if (head == NULL)
{
printf("List is already empty.");
}
else
{
toDelete = head;
head = head->next;

printf("\nData deleted = %d\n", toDelete->item);

free(toDelete);

printf("Successfully Delete First Node\n");
}
}
void deleteLastNode()
{
struct node *toDelete, *secondLastNode;

if (head == NULL)
{
printf("List is already empty.");
}
else
{
toDelete = head;
secondLastNode = head;

while (toDelete->next != NULL)
{
secondLastNode = toDelete;
toDelete = toDelete->next;
}

if (toDelete == head)
{
head = NULL;
}
else
{
secondLastNode->next = NULL;
}

free(toDelete);

printf("Successfully Deleted Last Node\n");
}
}
void deleteMiddleNode(int position)
{
int i;
struct node *toDelete, *prevNode;

if (head == NULL)
{
printf("List is already empty.");
}
else
{
toDelete = head;
prevNode = head;

for (i = 2; i <= position; i++)
{
prevNode = toDelete;
toDelete = toDelete->next;

if (toDelete == NULL)
break;
}
if (toDelete != NULL)
{
if (toDelete == head)
head = head->next;

prevNode->next = toDelete->next;
toDelete->next = NULL;

free(toDelete);

printf("Successfully\n");
}
else
{
printf("Invalid position unable to delete.");
}
}
}


 
Stack implementation using C  ||  Queue implementation using C