0% found this document useful (0 votes)
103 views54 pages

constructor

The document contains C++ code for multiple classes that perform various tasks like sorting arrays, calculating employee salaries, counting sarees by color, and more. Each class has private data members and public member functions to work with the data. Main functions are included to test the class functionality.

Uploaded by

Vishakh Krishnan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views54 pages

constructor

The document contains C++ code for multiple classes that perform various tasks like sorting arrays, calculating employee salaries, counting sarees by color, and more. Each class has private data members and public member functions to work with the data. Main functions are included to test the class functionality.

Uploaded by

Vishakh Krishnan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

Question 3

#include <iostream.n>
#include<conio.n>
#include<string.n>
class sarees
{
private:
int val;
public:
sarees() \\constructor to initialize value to zero
{
val=0;
}
void countsarees() \\to increment value by 1
{
val=val+1;
}
int getsarees()
{
return val;
}
};
void main()
{
sarees red,blue,green,other;
sarees string;
cout <<”enter a string of first letter of the colour:”;
char colour [100];
cin>> colour;
char * letter – colour;
for(int i = 0;i<str.len (letter);I ++)
{
if (islower(letter [i] )
{
letter[i] = to upper(letter[i]);
}
char cl = letter [i];
switch (cl)
{
case r:
red.countsarees();
break;
case b:
blue.countsarees();
break;
case g:
green.countsarees();
break;
default:
other.countsarees();
}
}
cout<<”no of red sares =”<<red.getsarees();
cout<<”no of green sares =”<<green.getsarees();
cout<<”no of blue sares =”<<blue.getsarees();
cout<<”no of other sares =”<<other.getsarees();

getch();
}
Question 6

#include<iostream.h>
#include<conio.h>
#include<string.h>
class telcall
{
private:
char name[20];
int n;
float amt;
int phno;

public:
telcall(int x;char y[20];int k)
{
phno=x;
for(int i=0;i<20;i++)
{
name[i]=y[i];
}
n=k;
}

void compute()
{
if(n>0&&n<101)
amt=500;
else if(n>100&&n<201)
amt=500+n;
else if(n>200&&n<301)
amt=500+(n*1.2);
else if(n<300)
amt=500+(1.5*n);
}

Void display()
{
cout<<setw(20)<<”phone number”<<”\t”
<<setw(20)<<”name”<<”\t”
<<setw(10)<<”no.of calls”<<”\t” <<setw(10)<<”bill
amount”;

cout<<setw(20)<<phno<<”\t” <<setw(20)<<name[]<<”\t”
<<setw(10)<<n<<”\t” <<setw(10)<<amt;
}

};

void main()
{
clrscr();
telcall t1;
int a,l;
char b[20];
cout<<”Enter the name of the customer,phone number and no.of calls
made”;
gets(b[]);
cin>>a>>l;
t1.telcall(a,b[],l);
t1.compute();
t1.display();
getch();
}

Question 11
#include<iostream.h>
#include<conio.h>
#include<string.h>
class string
{
private:
char str[100],rev[100];
public:
string()
{
for(int i=0;i<100;i++)
{
str[i]=0;
rev[i]=0;
}
}

void inputstring()
{
cout<<”enter a string (less than 100 letters)”;
gets(str[]);
}

void getprocess()
{
int l=str.len(str[]);
int j;
for(int k=l-1;k>=0;k--)
{
rev[j]=str[k];
j++;
}
cout<<”original string”;
puts(str[]);
cout<<”reversed string”;
puts(rev[]);
}
void findvalue()
{
int spaces=0;
for(int m=0;m<l;m++)
{
if(str[m]==” ”)
spaces++;
}
int words=spaces+1;
cout<<”no of words = ”<<words;
cout<<”no of spaces”<<spaces;
}

};

void main()
{
clrscr();
string s;
s.string();
s.inputstring();
s.getprocess();
s.findvalue();
getch();
}

Question 10
#include<iostream.h>
#include<conio.h>
#include<string.h>
class matrix
{
private :
int arr[50][50];
int m,n;
int prime(int);
public :
matrix()
{
m=0;
n=0;
for(int p=o;p<50;p++)
{
for(int q=0;q<50;q++)
{
arr[p][q]=0;
}
}
}

void getmat()
{
cout<<”enter the of m & n”;
cin>>m>>n;

for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
arr[i][j]=(i*i*i*)+(j*j*j);
}
}

}
void show()
{
for(int s=0;s<m;s++)
{
for(t=0;t<n;t++)
{
cout<<arr[s][t]
}
cout<<”\n”;
}
}

void calculations()
{
int sp=0,so=0;
if(m==n)
{
for(int d=0;d<m;d++)
{
if(prime(arr[d][d])==1)
sp+=arr[d][d];
}
else
cout<<”no diagonal found as it is not a square matrix”;

for(int c=1;c<m-1;c++)
{
for(int e=1;e<n-1;e++)
{
so+=arr[c][e];
}
}
cout<<”sum of primes in diognal”<<sp;
cout<<”sum of all elements except borders”<<so;
}
};

int matrix :: prime(int f)


{
int flag=1;
for(int w=2;w<f;i++)
{
if(f%w==0)
flag=0;
}
if(f==1||f==2)
flag=1;
return flag;
}

Question 7
# include<iostream.h>
# include <conio.h>
# include <string.h>
class employee
{
char empname[20];
int empcode;
double basicpay;
public:
employee();
employee(char[],int,double);
double salarycal();
};

employee::employee()
{
strcpy(empname,” ”);
empcode=0;
basicpay=0;
}

employee::employee(xempname[],int xempcode,double xbasicpay)


{
strcpy(empname,xempname);
empcode=xempcode;
basicpay=xbasicpay;
}

double employee::salarycal()
{
double salary,HRA,DA,SPA,TotalSalary = Null;
salary=HRA=DA=SPA=Null;
HRA=(30/100)*basicpay;
DA=(40/100)*basicpay;
salary=basicpay+HRA+DA;
if(empcode<=15&& salary<=15000)
{
SPA=(20/100)*salary;
if(SPA>2500)
SPA=2500;
}
if (empcode>15)
SPA=1000;
TotalSalary=salary+SPA;
return TotalSalary;
}

Question 2
# include <iostream.h>
# include <conio.h>
class sorter
{
private:
int ar[100];
public:
sorter()
{
for(int i=0;i<100;i++)
{
ar[i]=0;
}
}

void readlist();
void displaylist();
int indexofmin(int startindex);
void selectionsort();
};

void sorter::readlist()
{
for(i=100;i<100;i++)
{
cin>>arr[i];
}

void sorter::displaylist()
{
for(int i=0;i<100;i++)
{
cout<<arr[i]<<”\n”;
}
}

int sorter::indexofmin(int start)


{
int pos=-1;
int t;
t=ar[start];
for(int i=start+1;i<100;i++)
{
if(ar[i]<t)
{
pos=i;
break;
}
}
return pos;
}

void selectionsort()
{
int t;
for(int i=0;i<100;i++)
{
for(int j=i+1;j<100;j++)
{
if(ar[i]>ar[j])
{
t=ar[i];
ar[i]=ar[j];
ar[j]=t;
}
}
}
}

Question 1

#include<iostream.h>
#include<conio.h>
class magic
{
private:
int num[150];
int n;
public:
magic()
{
for(int i=0;i<150;i++)
{
num[i]=0;
}
}

magic(int nx)
{
n=nx;
}

void input_number()
{
cout<<”enter”<<n<<”numbers”;
for(int l=0;l<n;l++)
{
cin>>num[l];
}
}

void find_print_magic()
{
for(int b=0;b<n;b++)
{
check(num[b]);
}
}
};

void magic:: check(int t)


{
int x=t;
int rem=0,sum=0;
while(t>a)
{
rem=t%10;
sum+=rem;
t=t-rem;
t=t%10;
}
if(sum>9)
check(sum);
else if(sum<10)
{
if(sum==1)
cout<<x<<”is a magic number”;
else
cout<<x<<”is not a magic number”:
}
}

void main()
{
clrscr();
magic m;
int tx;
cout<<”enter the number elements”;
cin>>tx;
m.magic();
m.magic(tx);
m.input_number();
m.find_print_magic();
getch();
}
Question 4

#include<iostream.h>
#include<conio.h>
class prim_factors
{
private:
int num[200];
int size;
int prime(int);
public:
prime_factors()
{
for(int i=0;i<200;i++)
{
num[i]=0;
}
}

void readsize(int nx)


{
size=nx;
}

void get_number()
{
cout<<”enter”<<size<<”numbers”;
for(int j=0;j<size;j++)
{
cin>>num[j];
}
}

void show_primeFact()
{
for(int l=0;l<size;l++)
{
cout<<num[l]<<”-”;
int check=0;
for(int c=2;c<num[l];c++)
{
if(prime(c)==1)
{
check=1;
cout<<c;
}
}
if(check==0)
cout<<”none”;
}
}
};

int prime_fact :: prime(int f)


{
int flag=1;
for(int w=2;w<f;i++)
{
if(f%w==0)
flag=0;
}
if(f==1||f==2)
flag=1;
return flag;
}

Question 5

# include<iostream.h>
# include<conio.h>
class myarray
{
private:
int arr[100];
int n;
public:
myarray(int nn)
{
n=nn;
{

void readarray();
void displayarray();
int binarysearch(int);
};

void myarray:: readarray()


{
cout<<”enter the size of the array”;
cin>>n;
cout<<”enter the array”;
cin>>arr[i];
}

void myarray:: displayarray()


{
cout<<”the array is:”;
for(int i=0;i<n;i++)
{
cout<<arr[i]<<” ”;
}
}

int myarray:: binarysearch(int val)


{
int pos=-1;
int first=0;
int last=n-1;
while(POS==-1&&first<=last)
{
middle=(first+lat)/2;
if(arr[middle]==val)
POS=middle;
else if(arr[middle]<val)
first=middle+1;
else
last=middle-1;
}

if(POS>(-1))
{
cout<<” the position of element =”<<++POS;
return POS;
}
else
{
cout<<”unsuccessful search”
return -999;
}
}

Question 13

#include<iostream.h>
#include<conio.h>
#include<string.h>
class sum_matrix
{
private:
int mat[50][50];
int m,n;
public:
sum_matrix()
{
for(int i=0;i<50;i++)
{
for(int j=0;j<50;j++)
{
mat[i][j]=0;
}
}
}

void read_row_colum(int a,int b)


{
m=a;
n=b;
}

void readmatrix()
{
cout<<”enter”<<m*n<<”integer values”;
for(int i=0;i<50;i++)
{
for(int j=0;j<50;j++)
{
cin>>mat[i][j];
}
}
}

void show_mat()
{
for(int i=0;i<50;i++)
{
for(int j=0;j<50;j++)
{
cout>>mat[i][j];
}
cout<<”\n”;
}
}

void summatric()
{
for(int i=0;i<m;i++)
{
int sumr=0;
for(int j=0;j<n;j++)
{
cout<<mat[i][j];
sumr+=mat[i][j];
}
cout<<sumr;
cout<<”\n”;
}

for(int i=0;i<n;i++)
{
int sumc=0;
for(int j=0;j<m;j++)
{
sumc+=mat[j][i];
}
cout<<sumc;
}
}
};

void main()
{
clrscr();
sum_matrix s1;
s1.sum_matrix();
int x,y;
cout<<”enter the value of m and n”;
cin>>x>>y;
s1.read_row_column(x,y):
s1.readmatrix();
s1.show_mat();
s1.summatrix();
getch();
}

Question 14
#include<iostream.h>
#include<conio.h>
struct angle
{
int degrees;
intminutes;
};
angle sumangle(angle, angle);
void main()
{
clrscr();
angle a [3];
int i;
for (i=0; i<=1;i++)
{
cout<<”\n enter angle in degrees and minutes\n”;
cin>>a [i].degrees;
cin>>a [i].minutes;
}
a [2] = sumangle (a [0]; a [1]);
cout<<”\n the added value=”;
cout<<a [2].degrees<<”degrees”
<<a[2].minutes;
cout<<”minutes”;
getch()
}
angle sumangle (angle x angle y)
{
angle z;
z.degrees = x.degrees + y.degrees;
z. minutes = x.minutes + y.minutes;
if (z.minutes >=60)
{
z.minutes -=60;
z.degrees ++;
}
return z;
}
Question 12

#include<iostream.h>
#include<conio.h>
class set
{
int arr[50];
int n;
public:
set(int nm)
{
n=nm;
}

void readelement()
{
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
}

void displayElements();
int getsize();
int has(int ele)
{
for(int i=0;i<n;i++)
{
if(arr[i]==ele)
{
return 1;
}
}
return 0;
}

set intersection(set d)
{
set st(50);
int k,s=0;
for(int i=0;i<n;i++)
{
k=arr[i];
if(d.has(k))
{
sr.arr[s]=k;
s++;
}
}

st.n=s-1;
return st;
}

set union(set d)
{
set s;
for(int i=0;i<n;i++)
{
s.arr[i]=arr[i];
}
int k=i;
for(int i=0;i<d.n;i++)
{
p=d.arr[i];
if(!s.has(p))
{
s.arr[k]=p;
k++;
}
}
s.n=k;
return s;
}

};
Question 8

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
Class stock
{
Protected:
char title[50];
char author[50];
char publisher[100];
int noc;
float price;
float price R;
public:
stock();
void check(char tit[],char aut[],int n)
void display ();
};
stock::stock()
{
strcpy(titile, “ ”);
strcpy(author,” “);
strcpy(publisher,” “);
ner=0;
price=0;
price R=0;
}
stock::void check(char tit[],char aut[],int n)
{
int flag, flag 1,flag 2;
float price 1;
if(stremp(out,author==0)
{
flag 1=1;
}
if(n<=noc)
{
flag 2=1;

}
if(flag==1&&flag1==1&&flag2==1)
{
cout<<”Your book is issued”;
noc=noc-n;
price=n*price;
price R=price;
}
else
cout<<”Sorry!book cannot be issued”;
}
stock::void display();
{
cout<<”title”<<”\t”<<”author”<<”\t”<<”unit price”<<”\t”<<”price”<<”\n”
<<”number of copies left”;
cout<<title<<”\t”<<author<<”\t”<<unit price<<”\t”<<price<<”\n”
<<noc;
}

Question 9

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class sort
{
protected:
int item;
int arr[20];
public:
void inpdata();
void bubsort();
void bin search();
};
void sort::void inpdata();
{
int k=0,x;
for(int i=0; i<=49;i++)
{
cout<<”enter the item no”;
cin >>x;
for(int m=0;m<=I;M++)
{
if(arr[m]==x)
{
cout<<”duplicate”;break;
}
else
arr[i]=x;

}
}
void sort::void bubsort()
{
int t;
for(int i=0;i<50;i++)
{
for(int j=0;j<50;j++)
{
if(arr[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
}
void sort::binsearch();
{
int f,n,I,m,size,pos=-1;
f=0;
cout<<”enter array”;
cin>>n;
i=size-1;
cout<<”enter an element to be search”;
cin>>term;
while(f<=1)
{
m=(f+1)/2;
if(arr[n]==item)
{
pos=m;
break;
}
else
if(item>arr[m])
f=m+1;
else
i=m-1;
if(pos=-1)
cout<<”item not found”;
else
cout<<”item found at”<<pos;
}
Inheritance

Question 1

#include<iostream.h>
#include<conio.h>
class series
{
protected:
int n,a,b,c;
public:
void inputlimit();
void assign();
void generateseries();
};
class maxmin : public series
{
private:
int ar[100];
int s,gn,sn;
public:
void readarray();
void findmaxmin();
void printresult();
};
void series::inputlimit()
{
cout<<”enter the limit n of the series”;
cin>>n;
}

void series::assign()
{
a=0;
b=1;
}
void series::generateseries()
{
cout<<a;
cout<<b;
for(int i=3;i<=n;i++)
{
c=a+b;
cout<<c;
a=b;
b=c;
}
}
void maxmin::readarray()
{
cout<<”enter value s”;
cin>s;
cout<<”entert the elements of the array”;
for(int j=0;j<s;j++)
{
cin>>arr[j];
}
}
void maxmin:: findmaxmin()
{
sn=ar[0];
for(int k=1kk<s;k++)
{
if(arr[k]<=sn)
sn=arr[k];
}
gn=arr[0];
for(int k=1kk<s;k++)
{
if(arr[k]<=sn)
gn=arr[k];
}
}

void maxmn::printresult()
{
cout<<”fibinocci series”;
generateseries();
cout<<”the greatest number is”;
cout<<gn;
cout<<”the smaller no is”;
cin>>sn;
}
void()
{
maxmin m;
m.input();
m.assign();
m.readarray();
m.findmaxmin();
m.printresult();
getch();
}

Question 2

#include<iostream.h>
#include<conio.h>
class iscscores
{
private:
int number[6][2];
public:
iscscores();
int point();
};
class bestfour : public iscscores
{
void bestsubjects();
};
iscscores::iscscores()
{
int i,j;
for(i=o;i<6;i++)
for(j=o;j<2;j++)
cin>>number[i][j];
}
int iscscores::point()
{
int p=0;
for(i=o;i<6;i++)
{
if(a[i][1]<=90)
{
l=1;
p+=l;
}
if((a[i][1]>=80)&&(a[i][1]<=89))
{
l=2;
p+=l;
}
if((a[i][1]>=60)&&(a[i][1]<=69))
{
l=4;
p+=l;
}
if((a[i][1]>=50)&&(a[i][1]<=59))
{
l=5;
p+=l;
}
if((a[i][1]>=40)&&(a[i][1]<=49))
{
l=6;
p+=l;
}
if((a[i][1]>=30)&&(a[i][1]<=39))
{
l=7;
p+=l;
}
if((a[i][1]>=20)&&(a[i][1]<=29))
{
l=8;
p+=l;
}
if((a[i][1]>=10)&&(a[i][1]<=19))
{
l=9;
p+=l;
}
if((a[i][1]>=1)&&(a[i][1]<=9))
{
l=10;
p+=l;
}
}
return(p);
}

Recursion

Question 1

#include<iostream.h>
#include<conio.h>
class recursion
{
private :
int a,b,c, limit;
public :
recursion ();
void input ();
int fib (int n);
void generate-fibseries()
};
recursion : : recursion()
{
a=0,b=1,c=1;
}
void recursion : : generate-fibseries()
{
intput();
(out<<a<<endl<<b<<endl;
while (c < =limit)
{
cout <<c<<endl;
c = a + b;
a = b;
b = c;
}
}
int recursion : fib (int n)
{
if (n = = 1 : : n = = 0)
{
return (n);
}
else
{
return (fib (n – 1) + fib (n – 2));
}
Practicle

Question 3

#include<iostream.h>
#include<conio.h>
void teens();
void tens();
void hundreds();
void thousands();
void count(int,int);
void main()
{
int n;
cout<<”enter number”;
cin>>n;

int
ones[20]={,one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,f
ourteen,fifteen,sixteen,seventeen,eighteen,nineteen};
int tens[10]={,ten,twenty,thirty,forty,fifty,sixty,seventy,eighty,ninety};

if(n<20)
teens();
else if(n==20)
cout<<”twenty”;
else if(n<100&n>20)
tens();
else if(n==100)
cout<<”hundred”;
else if(n>100&&n<1000)
hundreds();
else if(n==1000)
cout<<” one thousand”;
else if(n>1000&&n<10000)
thousands();
else if(n==10000)
cout<<”ten thousand”;
else
cout<<”incorrect value”;
getch();
}

void teens()
{
cout<<ones[n];
}
void tens()
{
int l=count(10,n);
cout<<tens[l]<<” ”<<ones[n%10];
}

void hundreds()
{
int k= count(100,n);
cout<<ones[i]<<” ”<<”hundred ”;
if(n%100!=0)
{
cout<<” and”;
n=n%100;
if(n<20)
teens();
else if(n==20)
cout<<”twenty”;
else if(n>20)
tens();
}
}

void thousands()
{
int k=count(1000,n);
cout<<ones[k]<<”thousand”;
if(n%1000!=0)
{
n=n%1000;
hundreds();
}
}

void count(int a, int b)


{
int t=0;
while(b>=a)
{
b-=a;
t++;
}
}

Question 5

#include<iostream.h>
#include<conio.h>
void main()
{
inr a[200];
cout<<”enter the coded message”;
for(int i=0;i<200;i++)
{
cin>>a[i];
}
int n=str.len(a[]);
for(int i=n;n>=0;n--);
{
int k=0;
int d=0;
k=a[n]*10+a[n-1];
n--;
if(k<23)
{
k+=100;
n--;
}
t=k;
cout<<t;
}
}

Question 7

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a[20][20],b[20][20],c[20][20];
int t,m,n,I,k,l,r,c=0;
cout<<”enter size of array 1 and 2”
cin>>n>>m;
cout<<”enter the elements of array 1”;
for(i=o;i<n;i++)
{
cin>>a[i];
strcpy(c[i],a[i]);
}
cout<<”enter the elements of array 2”;
for(k=o;k<m;k++)
{
cin>>b[k];
strcpy(c[n+k],b[k]);
}
for(k=0;k<(m+n-2);k++)
{
for(l=k+1;l<m+n);l++)
{
t=strcmp(c[k],c[l]);
if(t>=0)
{
strcpy(d[k],c[l]);
strcpy(c[l],c[k]);
strcpy(c[k],d[k]);
for(i=m;i>0;i--)
if(strcmp(c[i],c[i-1]))
strcpy(d[0],c[i])
0++;
}
}
--0;
cout<<”the sorted array is”;
for(r=0;r>=0;r--)
cout<<”\n”<<c[r];

getch();
}
Question 8
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<”value of n”;
cin>>n;
inr a[100];
cout<<”enter the array”;
for(int i=100;i<n;i++)
{
cin>>a[i];
}
for(int i=100;i<n;i++)
{
for(int k=0;k<n-1;k++)
{
if(a[k+1]<a[k])
{
int t=a[k];
a[k]=a[k+1];
a[k+1]=t;
}
}
}
int j=1;
for(int i=0;i<n;i++)
{
cout<< a[i]<<”*”;
while(a[i]==a[i+1])
{
i++;
j++;
}
cout<<j;
cout<<”\n”;
}
Question 9
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int d1,d2,m1,m2,y1,y2;
cout<<”enter the date of end”;
cin>>d1>>m1>>y1;
cout<<”enter the starting date”;
cin>>d2>>m2>>y2;
int a[13]={,31,29,31,30,31,30,31,31,30,31,30,31};
int n=y1-y2;
int D=0;
if(n==0)
{
for(int i=m2;i<m1i++)
{
D+=a[i];
}
D+=d1;
D-=d2;
}
else
{D=365*(n-2);
for(int i=1;i<m1;i++)
{
D+=a[i];
}
D+=d1;
for(int i=m2;i<12;i++)
{
D+=a[i];
}
D-=d2;
}
cout<<”no of days =”;
cout<<D;
}
Question10

#include<iostream.h>
#incude<conio.h>
void main()
{
int a[20],b[20];
int n;
cout<<”enter the array”;
for(int i=0;i<20;i++)
{
cin>>a[i];
}
n=str.len(a[]);

for(int i=100;i<n;i++)
{
for(int k=0;k<n-1;k++)
{
if(a[k+1]<a[k])
{
int t=a[k];
a[k]=a[k+1];
a[k+1]=t;
}
}
}

if(n%2==0)
int c=n/2;
else
{
int c=n/2;
c++
}
int r=c+1;
int l=c-1;
b[c]=a[0];
for(int i=1;i<=n;i++)
{
if(i%2==0)
{
b[l]=a[i];
l--;
}
else
{
b[r]=a[i];
r++;
}
}
}

Question 12

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int arr[12][12];
cout<<””enter the valur of n;
cin>>n;
t=n*n;
int q=0;
while(n>=n/2&&q<=n/2)
{
for(int i=n;i>q;i--)
{
arr[n][i]=t;
t--;
}
for(int i=n;i>q;i--)
{
arr[i][q]=t;
t--;
}
for(int l=q;l<n;l++)
{
arr[q][l]=t;
t--;
}
for(int l=q;l<n;l++)
{
arr[l][n]=t;
t--;
}

n--;
q++;
}
arr[n][q]=t;

for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<arr[i][j];
}
cout<<”\n”;
}

getch();

Question 13

#include<iostream.h>
#include<conio.h>
void main()
{
char arr[100];
cout<<”enter the sentence”;
gets(arr[]);
int l,m,c=0,k=0;
cout<<”enter the two word numbers”;
cin>>l>>m;

for(int i=0;i<str.len(arr[]);i++)
{
if(arr[i]=” ”)
{
int c++;
if(l==c)
{
for(int j=k+1;j<i;j++)
{
if(arr[j]==z)
arr[j]=a;
else if(arr[j]==Z)
arr[j]=A;
else
arr[j]=arr[j]++;
}
}

if(m!=l&&m==c)
{
for(int j=k+1;j<i;j++)
{
if(arr[j]==z)
arr[j]=a;
else if(arr[j]==Z)
arr[j]=A;
else
arr[j]=arr[j]++;
}
}
k=i;
}
getch();
}
Question 14

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
int d,m,y;
cout<<”enter the project completion date”;
cin>>d>>m>>y;
cout<<”no of days”;
cin>>n;
int a[13]={,31,29,31,30,31,30,31,31,30,31,30,31};
n=n-d;
if(m==1)
m=12;
y--;
else
m=m-1;
for(int i=n;n>=0;n--)
{
if(a[m]!=0)
a[m]--;
else if(a[m]==0)
m--;
}

cout<<”date given on is:”;


coit<<a[m]<<” ”<<m<<” ”<<y;
}

Question 11

#include<iostream.h>
#include<conio.h>
int rep()
{
for(int i-0;i<str.len(a[]);i++)
{
flag=0;
for(int j=0;j<7;j++)
{
if(j!=i)
{
if(a[j]==a[i])
{
flag=1;
}
}
}
}
return flag;
}

int lower()
{
int flag=0;
for(int i=0;i<7;i++)
{
int k=a[i];
if(k!>=65&&k!<=90)
{
flag=1;
}
}
return flag;
}

void main()
{
clrscr();
int n;
char a[6];
cout<<”enter the length”;
cin>>n;
cout<<”enter the code”;
gets(a[]);

if((str.len(a[])==n)&&n<=6&&rep==0)
{
int flag=1;
for(int i=0;i<n;i++)
{
if((a[i]!=”A”)|| (a[i]!=”C”)|| (a[i]!=”E”)|| (a[i]!=”G”)|| (a[i]!
=”I”)|| (a[i]!=”K”))
{
f=0;
}
}

if(flag==1)
{
cout<<”VALID”;
}

else if(str.len(a[])<7&&str.len(a[])!=n)
{
cout<<”INVALID! string length not as specified”;
}

else if(str.len(a[])>=7)
{
cout<<”INVALID! string length should not exceed 6 characters”;
}

else if(rep()==1)
{
cout<<”INVALID! repetition of characters not allowed ”;
}

else if(lower()=1)
{
cout<<”INVALID! only upper case letters permitted”;
}

else if(flag==0)
{
cout<<”INVALID!only alternate characters valid”;
}
getch();
}

You might also like