Use one dimensional array to solve the following problem. Read 20 integers from data file, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read. Provide for the Worst case in which all 20 integers are different. Use the smallest possible array To solve this problem



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr[20];
for (int i=0;i<20;i++)
                {
                cout<<"enter the element no "<<i+1<<endl;
                cin>>arr[i];
                }

for (i=0;i<20;i++)
                {
                for (int j=0;j<20;j++)
                                {
                                if (i!=j)
                                {
                                                if (arr[i]==arr[j])
                                                arr[j]=0;
                                                else
                                                continue;
                                }
                                else
                                continue;
                                }
                }

for (i=0;i<20;i++)
                {
                if (arr[i]<=100&&arr[i]>=10)
                cout<<arr[i]<<endl;
                else
                continue;
                }

getch();
}



OUTPUT:

C++ Programme for a function to encode a string that is passed to it. The string should get converted into an unrecognizable form.



#include<iostream.h>
#include<conio.h>
#include<string.h>


#include<stdio.h>


void encode(char str1[],int l);


int main()
{
               char str[30];
               cout<<"Enter an string:";
               gets(str);
               int len=strlen(str);
               encode(str,len);
               return 0;
}

void encode(char str1[],int l)
{
               int i;
               for(i=0;i<l;i++){
                              str1[i]=str1[i]+10;
               }
               cout<<"\nThe encoded string is:"<<endl;
               for(i=0;i<l;i++){
                              cout<<str1[i];
               }
               cout<<"\nThe proper string is:"<<endl;
               for(i=0;i<l;i++)
                              str1[i]=str1[i]-10;
               for(i=0;i<l;i++)
                              cout<<str1[i];
}





OUTPUT:

C++ Programme for A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not.



#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class stock
{
               char author[50];
               char title[50];
               char pub[50];
               double price;
               int numcopies;
   public:
               stock();
               int access_title(char a[]);
               void input();
               void getdata(int);

};
stock::stock()
{
                  char author[50]={"abc"};
                  char title[50]={"efg"};
                  char pub[50]={"hij"};
                  price=500;
                  numcopies=50;
}
int stock::access_title(char a[])
{
               if(strcmp(title,a))
                              return 0;
               else return 1;
}
void stock::getdata(int num)
{
               if(numcopies>=num)
                              cout<<"\nCost of "<<num<<" books is Rs. "<<(price*num);
               else
                  cout<<"\nSorry! These many copies are unavailable!";
}
void stock::input()
{
               cout<<"\nTitle: ";
               gets(title);
               cout<<"\nAuthor:";
               gets(author);
               cout<<"\nPublisher:";
               gets(pub);
               cout<<"\nPrices:";
               cin>>price;
               cout<<"\ncopies available:";
               cin>>numcopies;
}

void main()
{
   clrscr();

   stock obj[2];
   int n;
   char ttle[50];

   cout<<"Enter details of 3 books";
   for(int i=0;i<2;++i)
               obj[i].input();

   cout<<endl;
   cout<<"\n Enter title of required book\n";
   gets(ttle);

   for(i=0;i<2;i++)
   {
               if(obj[i].access_title(ttle))
               {
                                             cout<<"\nHow many copies? ";
                                             cin>>n;
                                             obj[i].getdata(n);
               }
               else
                                             cout<<"\nBook unavailable";
   }
   getch();
}




OUTPUT: