Posts

Showing posts from October, 2020

Write a program to sort the given array using Bubble Sort.

Image
  Write a program to sort the given array using Bubble Sort.     #include <stdio.h>   void bubbleSort(int array[], int size) {   for (int step = 0; step < size - 1; ++step)   {         int swapped = 0;       for (int i = 0; i < size - step - 1; ++i) {         if (array[i] > array[i + 1]) {                 int temp = array[i];         array[i] = array[i + 1];         array[i + 1] = temp;         swapped = 1;       }     }       if (swapped == 0)       break;   } }   void printarray(int array[], int size) {   for (int i = 0; i < size; ++i)...

Write a program to search an element using Binary Search.

Image
Write a program to search an element using Binary Search.   #include <stdio.h> int binarySearch(int array[], int find, int low, int high); int main(void) {   int array[100],size,find;   printf("Enter size of array:\n");   scanf("%d",&size);   printf("Enter-- \n");   for(int i=0;i <size; i++)   {       printf("Element[%d]",i);       scanf("%d",&array[i]);   }  printf("Enter Element to be search:\n");   scanf("%d",&find);   int result = binarySearch(array,find, 0, size - 1);   if (result == -1)     printf("Not found");   else     printf("Element is found at index %d", result); } int binarySearch(int array[], int find, int low, int high)                        ...

Write a program in C++ to create a base class shape and derive two classes named Circle and Square from it. Create and initialize objects from these classes using appropriate constructors.

 #include<iostream> #include<string.h> using namespace std; class Shape { public: double radius; double side; //constructor to assign initial values to side and circle; Shape() { side=0;; radius-=0; } void get_data() { cout<<"\nEnter side of square to compute area  :"; cin>>side; cout<<"\nEnter radius of circle to compute area  :"; cin>>radius; } virtual void display_area() { } }; class Square: public Shape { public: void display_area() { cout<<side; cout<<"\nArea of Square = "<<(side*side); } }; class Circle : public Shape { public: void display_area() { cout<<"\nArea of Circle= "<<(3.14*radius*radius); } }; int  main() { Shape *s; Square t; t.get_data(); s=&t; s->display_area(); Circle r; r.get_data(); s=&r; s->display_area(); return 0; }

[ C++ program] Assume that a bank maintains two kinds of accounts for customers, | | one called as savings account and the other as current account. | | The savings account provides compound interest and withdrawal facilities but no cheque book facility. | | The current account provides cheque book facility but no interest. | | Current account holders should also maintain a minimum balance | | and if the balance falls below this level, a service charge is imposed. | | Create a class account that stores customer name, account number and type of account. | | From this derive the classes curacct and savacct to make them more specific to their requirements.

  | Assume that a bank maintains two kinds of accounts for customers, | | one called as savings account and the other as current account. | | The savings account provides compound interest and withdrawal facilities but no cheque book facility. | | The current account provides cheque book facility but no interest. | | Current account holders should also maintain a minimum balance | | and if the balance falls below this level, a service charge is imposed. | | Create a class account that stores customer name, account number and type of account. | | From this derive the classes curacct and savacct to make them more specific to their requirements. | | Include necessary member functions in order to achieve the following tasks: | | ...

c program to print advance date (edx course solution ) using structure:

Image
 #include <stdio.h> struct date {         int year;         int month;         int day;     }; /* function prototypes */ void printDate(struct date); void readDate(struct date *); struct date advanceDay(struct date);  int main(void) { struct date today, tomorrow; readDate(&today); printf("You Insert:\n"); printDate(today); printf("Advance Date:\n"); tomorrow = advanceDay(today); printDate(tomorrow); return 0; } void readDate(struct date *today) {     printf("Enter Date in (YYYY/MM/DD) format:\n");     printf("Enter Year:\n");     scanf("%d",&today->year);     printf("Enter Month:\n");      scanf("%d",&today->month);      printf("Enter Date:\n");       scanf("%d",&today->day); } void printDate(struct date today) {     printf("%02d/%02d/%4d\n",today.month,today.day,today...

C Program to implement sparse matrix using array;

Image
 #include<stdio.h>     int main()  {           int sparseMatrix[100][100],rows,columns;      printf("Enter number of rows and columns of sparse Matrix:\n");     scanf("%d%d",&rows,&columns);     printf("Enter the elemnts of a spare Matrix:\n ");     for(int i=0; i<rows;i++)     {         for(int j=0; j<columns;j++)         {            printf("Element[%d][%d]:",i,j);            scanf("%d",&sparseMatrix[i][j]);         }     }                      int size = 0;      for (int i = 0; i < 4; i++)      {         for (int j = 0; j < 5; j++)         {             if ...

Perform all operation in a singly linked list using C language:

Image
#include <stdio.h> #include<stdlib.h> struct S_list {     int age;     struct S_list *next; }; struct S_list *read_list(); struct S_list *create_list(int num); void print_list(struct S_list * start); void search(struct S_list *start,int find); void delete_list( struct S_list *start); int main() {  struct S_list *start;  int find;  start=read_list();  printf("Data in the list:\n");  print_list(start);  printf("Enter the element to be search:\n");  scanf("%d",&find);  search(start,find);  delete_list(start);  printf("Data in the list:\n");  print_list(start);  printf("\n\nCodes Written by-Vikas kumar\n");  printf("\n\n on %s\n",__DATE__); return 0; } struct S_list *read_list() {     struct S_list* start,*newPtr,*endptr;      int size;     printf("Enter number of elements\n");     scanf("%d",&size);     for(int i=0; i<size; i++) ...