Posts

Introduction to ChatGPT: Explain what ChatGPT is, how it works, and what it is used for.

Introduction to ChatGPT ChatGPT is an AI language model developed by OpenAI that is based on the GPT (Generative Pre-trained Transformer) architecture. It is designed to generate natural language text that is both coherent and contextually relevant. ChatGPT is trained on a vast amount of text data, including books, articles, and websites. During training, it learns the patterns and structures of natural language and uses this knowledge to generate text in response to prompts. The model works by predicting the most probable next word in a sequence of words based on the previous words in the sequence. It does this by assigning a probability score to each word in its vocabulary based on the context of the prompt. The word with the highest probability score is then selected as the next word in the sequence. This process is repeated until the desired length of the text is generated. ChatGPT is used for various applications, including chatbots, content generation, language translation, an...

Write a program for employees database

Write a program for employees database PROGRAM: #include<iostream> #include<stdio.h> #include<stdlib.h> using namespace std; class staff{ int code; char name[10]; public: void set_details(){ cout<<"Enter code : "; cin>>code; cout<<"Enter Name : "; cin>>name; } void get_details(){ cout<<"\ncode : "<<code<<"\t"<<"name : "<<name; } }; class edu:public staff{ char educat[10]; public: void set_edu(){ cout<<"\nEnter qualification :"<<endl; cin>>educat; } void get_edu(){ cout<<"\nqualification : "<<educat; } }; class officer:public edu{ char grade[2]; public: void set_grade(){ cout<<"Enter grade : "; cin>>grade; } void get_grade(){ cout<<"\n...

Hybrid Inheritance In cpp

Hybrid Inheritance In cpp PROGRAM: #include<iostream> using namespace std; class A{ public: A(){ cout<<"\n grand parent"; } }; class B:public A{ public: B(){ cout<<"\n parent1"; } }; class C:public A{ public: C(){ cout<<"\n parent2"; } }; class D:public B,public C{ public: D(){ cout<<"\n child class"; } }; int main(){ D d; return 0; }

Multiple Inheritance In cpp

Multiple Inheritance In cpp PROGRAM: #include<iostream> using namespace std; class A{ public: A(){ cout<<"\n parent1"; } }; class B{ public: B(){ cout<<"\n parent1"; } }; class C:public A,public B{ public: C(){ cout<<"\n child"; } }; int main(){ C c; return 0; }

Multi Level Inheritance In cpp

Multi Level Inheritance In cpp PROGRAM: #include<iostream> using namespace std; class A{ public: A(){ cout<<"\n grand parent"; } }; class B:public A{ public: B(){ cout<<"\n parent1"; } }; class C:public B{ public: C(){ cout<<"\n child"; } }; int main(){ C c; return 0; }

What is default arguments in cpp

What is default arguments in cpp PROGRAM: #include<iostream> using namespace std; class interest{ float p,r,n; public: void setdata( ){ cout<<"\n P: "; cin>>p; cout<<" R: "; cin>>r; cout<<" N: "; cin>>n; calc(p,n,r); calc(p,n);//!uses default arguments } float calc(float p,float n,float r=0.25){ //!default argument cout<<"\n\t\t\t Interset is : "<<(p*r*n); } }; int main(){ interest i; i.setdata(); return 0; }

Inline Function In cpp

Inline Function In cpp PROGRAM: #include<iostream> #include<stdio.h> using namespace std; inline int addition(int a,int b){ return (a+b); } int main(){ int x,y,add; char ch; do{ cout<<"Enter NUM1 & NUM2 : "; cin>>x>>y; add=addition(x,y);//!the compiler places a copy of the code here cout<<"\nNUM1 + NUM2 : "<<add; cout<<"\n\t\t\t Enter y to continue : "; cin>>ch; }while(ch=='y'); return 0; }

Nested Member In cpp

Nested Member In cpp PROGRAM: #include<iostream> using namespace std; class student{ char name[10]; int roll_no; void print(){ cout<<"\n\n Entered Name : "<<name<<"\n\n Entered roll no : "<<roll_no; } public: void setdata(){ cout<<"\nEnter name : "; cin>>name; cout<<"\nEnter roll no : "; cin>>roll_no; print(); //!nesting of member function } }; int main(){ student s; s.setdata(); return 0; }

How to overload function in cpp

Overload Function In cpp PROGRAM: #include<iostream> using namespace std; void sub(float i,float j){ cout<<"\nsub : "<<(i-j); } void sub(int i,int j){ cout<<"\nsub : "<<(i-j); } void add(int i,int j){ cout<<"\nadd :"<<(i+j); } void add(float i,float j){ cout<<"\nadd :"<<(i+j); } int main(){ int a,b,ad; float x,y; cout<<"integer value are : "; cin>>a>>b; cout<<"float value are : "; cin>>x>>y; add(a,b); add(x,y);//!arguments have different data types sub(a,b); sub(x,y);//!!arguments have different data types return 0; }

Impemnt Producer Consumer Problem In cpp or c

Impemnt Producer Consumer Problem In cpp or c PROGRAM: #include<stdio.h> #include<stdlib.h> #include<pthread.h> # define BufferSize 3 int mutex=1,full=0,empty=3,x=0; void *producer(); void *consumer(); int BufferIndex=0; char *BUFFER; pthread_cond_t Buffer_Not_Full=PTHREAD_COND_INITIALIZER; pthread_cond_t Buffer_Not_Empty=PTHREAD_COND_INITIALIZER; pthread_mutex_t mVar=PTHREAD_MUTEX_INITIALIZER; int wait(int); int Signal(int); int main() { int n; pthread_t ptid,ctid; BUFFER=(char *) malloc(sizeof(char) * BufferSize); printf("\n1.Producer\n2.Consumer\n3.Exit"); while(1) { printf("\nEnter your choice:"); scanf("%d",&n); switch(n) { case 1: if((mutex==1)&&(empty!=0)){ //producer(); pthread_create(&ptid,NULL,producer,NULL); pthread_join(ptid,NULL);} else printf("Buffer is full!!"); break; case 2: if((mutex==1)&...

how to return obj in cpp

How To Return Object  PROGRAM: #include<iostream> using namespace std; class Complex{ int x,y; public: void setdata(int a,int b){ x=a; y=b; } void showdata(){ cout<<"\nx = "<<x<<" y = "<<y; } friend Complex addition(Complex,Complex); }; Complex addition(Complex a,Complex b){ Complex temp; temp.x=a.x+b.x; temp.y=a.y+b.y; return temp; } int main(){ Complex c1,c2,c3; c1.setdata(3,2); c2.setdata(2,3); cout<<"\n c1:"; c1.showdata(); cout<<"\n c2:"; c2.showdata(); c3=addition(c1,c2); cout<<"\n c3:"; c3.showdata(); return 0; }

Static function and static variable in cpp

Static variable and Static method in cpp PROGRAM: #include<iostream&gt using namespace std; class test{ int code; static int Count; public: void set_code(void){code=++Count;} void show_code(void){ cout<<"Object number : "<<code<<endl; } static void show_Count(void){ cout<<"Count : "<<Count<<endl; } }; int test:: Count; int main(){ test t1,t2; //!when 1st obj. created static Count=0 t1.set_code();//!t1=1,count=1 test::show_Count();//!because Static function t2.set_code(); //!t2=2,count=2 test::show_Count();//!count=2 test t3;//!count=2 t3.set_code();//!t3=3,count=3 test::show_Count();//!count=3 t1.show_code(); t2.show_code(); t3.show_code(); return 0; }

Thread Programming in CPP

Simple Thread Programming in CPP PROGRAM: #include&ltiostream&gt #include&ltpthread.h&gt using namespace std; void *Thread() { cout&lt&lt"HELLO"; } int main(){ pthread_t t_id; pthread_create(&t_id,0,&Thread,0); pthread_join(t_id,NULL); return 0; }

Write a program for bank which has class bank,deposit,withdraw in cp

#include<iostream> using namespace std; static long int id; class bank{ protected: char name[10]; double money=2000; int acc_no; public: void setdetails(){ cout<<"\n Enter name :"; cin>>name; cout<<"\nyour acc_no(PLEASE NOTE DOWN) : "<<id; acc_no=id; id++; cout<<"\n you have to deposite '2000rs' for opening account in pruthvi bank\n THANK YOU"; cout<<"\nPlease keep balance above 2000rs"; } }; class deposite:virtual public bank{ public: void set_deposit(){ float temp; cout<<"\n Enter deposite value : "; cin>>temp; money=money+temp; cout<<"\n Now money : "<<money<<endl; } }; class withdrawl:virtual public bank{ public: void set_with(){ float temp; cout<<"\n Enter withdrawl value : "; ...

Write a program to illustrate array of object

Array Of Object PROGRAM: #include<iostream> using namespace std; class employee{ int age; char name[10]; public: void getdata(){ cout<<"\nEnter name :"; cin>>name; cout<<"\nAge :"; cin>>age; } void print(){ cout<<"\nEntered name :"<<name<<"\tAge: "<<age; } }; int main(){ employee Manager[3],Worker[5]; int i; for(i=0;i<3;i++){ Manager[i].getdata(); Manager[i].print(); } for(i=0;i<5;i++){ Worker[i].getdata(); Worker[i].print(); } return 0; }

Binary search in C

Image
Binary search in C Binary Search: in computer science,  binary search , also known as half-interval  search , logarithmic  search , or  binary chop, is a  search  algorithm that finds the position of a target value within a sorted array. It necessary that given data is sorted in ascending order or descending order. below is the program of binary search for ascending ordered data. PROGRAM   : #include <stdio.h> #include <stdlib.h> int main(int n,int a[10]) { int i,mid,key,ub,lb; printf("How many numbers you wants to enter="); scanf("%d",&n); lb=0; ub=n-1; printf("\n%d elements are=",n); for(i=0;i<n;i++){ printf("\na[%d]=",i); scanf("%d",&a[i]); } printf("\nKey=",n); scanf("%d",&key); mid=(lb+ub)/2; while(a[mid]!=key && lb<=ub){ if(key<a[mid]){ ub=mid-1; } ...

Stack using C

Image
Stack using C PROGRAM : For Stack using C #include <stdio.h> #include <stdlib.h> #define MAX 4 struct stack { int a[MAX]; int top; }st; int stfull(){ if(st.top>=MAX-1)return 1; else return 0; } int push(int val){ st.top++; st.a[st.top]=val; } int stempty(){ if(st.top==-1)return 1; else return 0; } int pop(){ st.top--; return 0; } int display(){ int i; if(stempty()==1)printf("\nstack is empty\n"); else{ printf("\n"); for(i=st.top;i>=0;i--){ printf("|%d|",st.a[i]); } } return 0; } /* Main function */ int main() { int val; int choice; st.top=-1; label: printf("\nselect the choice\n"); printf("1=push\n2=pop\n3=peep\n4=display\n5=clear screen\n"); scanf("%d",&choice); switch(choice){ case 1: if(stfu...