Upload
akshiyuvi
View
217
Download
0
Embed Size (px)
Citation preview
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
1/53
LOVELY PROFESSIONAL UNIVERSITY
ASSIGNMENT OF P & TINFOSYS CONNECT PROGRAM
AKHIL SHARMA Reg No. 10807224SEC D1803 BATCH 2
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
2/53
P & T ASSIGNMENT
DAY 1 ASSIGNMENT
1.
SOL
a. 20.
b.10.
2.
SOL
a. The sky is the limit
b. The sky is
c. Garbage value or T
d. The sky is the limit
e.
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
3/53
f. In this statement ; is extra so on removing it weget - ermination
g. % - garbage value.
h. U
3.
SOL
a. 5.00
b.4.5
c. 3.00
4.
SOL
2004000
DEBUGGING EXERCISE1 To identify error in program and after correctionwrite output !
SOL
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
4/53
#include
#include
#define PI 3.14159int main()
{
int iRadius,iCircumference;
float fPerimeter;
float fArea;iCircumference = PI;
iRadius=5;
fPerimeter=2.0*iCircumference*iRadius;
fArea=iCircumference*iRadius*iRadius;
printf("%f,%d",fPerimeter,fArea); // %f should beused to display
FArea
getch();
return 0;}
Output
30,45
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
5/53
2 Find error in each of the following segments
SOL
a. if(iNumber1+iNumber2 = iNumber3 &&iNumber2>0)
printf( );
ANS- The correct statement is as follows
if(((iNumber1+iNumber2)==iNumber3)&&( iNumber2>0))
printf( );
b. If(iCode>1);
iValue= iValue2+iValue3
else
iValue1=0
ANS- The correct statements are as follows :-
If(iCode>1)
iValue= iValue2+iValue3;
else
iValue1=0;
c. If(iTemp
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
6/53
printf(Sign is negative);
ANS- The correct statements are as follows :-
If((iTemp
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
7/53
printf(My name is XXX\n);
} while(cName=1)
ANS- Errors :- Semi-colon is required at the end toterminate do-while
Loop. Example-
do{
}while();
c. iIndex1 =1; iIndex2 = 0;
for(;iIndex1+iIndex2
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
8/53
printf(%f,iIndex3);
ANS - The above code does not have any error . theoutput of the
following code will be 0.0000
4. Identify error if any in each case of followinginitialization
SOL-
a. int iNumber[]={0,0,0,0,0};
ANS The above initialization is correct.
b. float fItem[3][2] = {0,1,2,3,4,5};
ANS The above initialization is correct.
c. char cWord[]={A,R,R,A,Y};
ANS The above initialization is correct.
d. float fArray[2,4] = {(0,0,0,0)(1,1,1,1)};
ANS The above initialization is wrong , the rows andcolumns cannot
Be initialized in the same square brackets.
e. float fResult[10]=0;
ANS The above initialization is not correct ,either sizeshould not be
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
9/53
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
10/53
sum=sum+a[i];
}
printf("\n The sum is %d ",sum);return 0;
}
So there were two error in the programs , one isallocating extra
memory during input and second is not using &while inputing
the data.
The output of the program depends upon the valuesinserted by
the user .
6.
SOL-
#include
#include
int main(int argc , char **argv)
{
double dPrice,dDiscount;
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
11/53
double dPriceAfterDiscount,dNetPrice;
printf("Enter the price of product(INR) ");
scanf("%lf",&dPrice);fflush(stdin);
printf("Enter sales tax(in %%) ");
scanf("%lf",&dSalesTax); // Undefined symbol
fflush(stdin);
if(dPrice>500.0)dDiscount=25.0;
} // Should have an opening
else{ // Not allowed
dDiscount=15.0;
}printf("the price of product:%2lf\n ",dPrice);
printf("Discount:%2lf%%\n ",dDiscount); // %% is notallowed
printf("Sales tax:%2lf%%\n ",dSalesTax) // semicolonis missing
and %% is notallowed
dPriceAfterDiscount=dPrice-((dPrice*dDiscount)/100.0);
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
12/53
dNetPrice=dPriceAfterDiscount+((dPriceAfterDiscount*dSalesTax)
/100.0); // Statement missing -- ( )
printf("the price after Discount:%2lf\n",dPriceAfterDiscount);
printf("Net price :%2lf\n ",dNetPrice);
getch();
return 0;
}
After removing errors output will be -
Output
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
13/53
ASSIGNMENT DAY2
Q1.#include
#include
#include
int main()
{
char cname[40];
floatihour_rate,gross_pay,fover_time,ihour_worked
float tax,net_pay;
coutcname;
coutihour_rate;
coutihour_worked;
if(ihour_worked
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
14/53
}
coutfover_time;gross_pay=ihour_rate*ihour_worked
+ihour_rate*fover_time;
cout
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
15/53
getch();
return 0;
}Q2.
#include
#include
# define error 25
int fnemployeeNameValid(char name[15]);int main()
{
clrscr();
printf(Enter the name of employee);
gets(name);fnemployeeNameValid(name);
if(count>7)
{
printf(name is valid);
}
else
{
printf(invalid name);
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
16/53
printf(Error %d,error);
}
getch();}
int fnemployeeNameValid(char name[15])
{
char na[15];
int count=0;for(i=0;i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
17/53
}
return(count);
}Q3.
#include
#include
#include
#includevoid main()
{
char name[20];
int num=0;
coutname;
for(int i=0;i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
18/53
num=num+1;
}}
cout
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
19/53
d=check(name1,name2);
cout
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
20/53
#include
#include
#includelong int fnGenerateTelNumber(char s);
int main()
{
char *s;
long int m;printf(Enter the number );
scanf(%s,&s);
m=fnGenerateTelNumber(s);
printf(No is :- ln,m);
getch();}
long int fnGenerateTelNumber(char s);
{
char *t;
int n;
n=atoi(t);
print(Equivalent value is : %d,n);
return(n);
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
21/53
}
Q6.
#include#include
#include
#include
struct dob
{short int day;
short int month;
short int year;
}dateofbirth;
void main()
{
char cmonth[12][12]={"january","february","march","april","may","june","july","august","sep","oct","nov","dec"};
cout
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
22/53
cin>>dateofbirth.day;
coutdateofbirth.month;coutdateofbirth.year;
cout
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
23/53
}dateofbirth;
void main(){
int d;
char cmonth[12][12]={"january","february","march","april","may","june","july","august","sep","oct","nov","dec"};
coutdateofbirth.day;
coutdateofbirth.month;
coutdateofbirth.year;
cout
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
24/53
cout
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
25/53
cout
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
26/53
if(dateofbirth.day>=1 &&dateofbirth.day=1 &&dateofbirth.day=1 && dateofbirth.day
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
27/53
}
}else
return 0;
}
Q8.
#includevoid main(){int A[20], N, Temp, i, j;clrscr();printf(\n\n\t ENTER THE NUMBER OF TERMS: );scanf(%d,&N);
printf(\n\t ENTER THE ELEMENTS OF THEARRAY:);for(i=1; i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
28/53
A[j] = Temp;}printf(\n\tTHE DECENDING ORDER LIST IS:\n);
for(i=N; i>=0; i--)printf(\n\t\t\t%d,A[i]);getch();}
Q9.#includevoid main(){
int A[20], N, Temp, i, j;clrscr();printf(" \n\n\t ENTER THE NUMBER OF employs...:
");scanf("%d", &N);
printf(" \n\t ENTER THE TELEPHONE NO. OFEMPLOYES...:");
for(i=0; i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
29/53
A[j+1] = A[j]; j = j-1;
}A[j+1] = Temp;}
printf(" \n\t THE ASCENDING ORDER LISTIS...: \n ");
for(i=0; i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
30/53
for(i=0;i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
31/53
{
mid=(High+low)/2
if(a[mid]
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
32/53
#include
#include
void main(){
int n,m1=0,m2=0,m3=0,total=0,t1=0,adm=0;
printf(Enter no of students :- );
scanf(%d,&n);
for(i=0;i=60&& m2>=50&& m3>=40))||total>200||t1>=150)
adm++;
}
printf(No of students passed 4 admission are :-
%d,adm);
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
33/53
getch();
}
Q 12
#include
#include
#include#include
void main( )
{
char ch[30];
int n,l,m;printf(Enter the string :);
gets(ch);
n=strlen(ch);
printf(Enter the starting and ending no from
which uwant to extract the data)
scanf(%d%d,&l,&m);
for(int i=l;i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
34/53
{
printf(%c,ch);
}getch( ); }
Q13
#include
#include#include
#include
struct cricket
{
char name;char tname;
int avg;
}c1;
void main()
{
int a[50];
for(i=0; i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
35/53
{
printf(Enter name of player : );
gets(c1.name);
printf(Enter name of team : );
gets(c1.tname);
printf(Enter avg of player : );
scanf(%d.&avg);}
for(i=0; i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
36/53
Q14#include
#include
void fnOccur(char name[20],char c);
void fnDel(char name[20],char c);
void main(){
char name[20],ch;
printf(enter the string : );
gets(name);
printf(enter the character );scanf(%c,&ch);
fnOccur(name,ch);
fnDel(name,ch);
getch();
}
void fnOccur(char name[20],char c)
{
char na[20];
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
37/53
char d;
int Count;
for(i=0;i
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
38/53
Q15
#include
#includevoid fnDayname(int m);
void main()
{
int n;
printf(Enter any number b/w 1-7);scanf(%d,&n);
fnDayName(n);
getch();
}
void fnDayname(int m){
int a;
switch(a)
{
Case 1: printf (Monday);
break;
Case 2: printf (Tuesday);
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
39/53
break;
Case 3: printf (Wednesday);
break;Case 4: printf (Thursday);
break;
Case 5: printf (Friday);
break;
Case 6: printf (Saturday);break;
Default: printf (Monday);
break;
}
}
DAY 3 ASSIGNMENT
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
40/53
ASSIGNMENT 1 : Identify test cases using BoundaryValue analysis
SOL
Float fnComputeRateofInterest (int iAmount)
{
If(amount>=5000 && amount=10001 && amount=15001 && amount=20001 && amount
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
41/53
{
Rate=0.11;
}
else if(amount>=25001 && amount5000 and
Errorin
fnComputeRate
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
42/53
Interest_4000
RateofInterest withamount =4000
amount5000 andamount5000 andamount5000 andamount5000 andamount5000 andamount5000 andamount5&
8/7/2019 Akhil Sharma Reg No 10807224 Batch 2
46/53
3. Emp_tel_no _ Emp_id_fail
Typeinvalid idand click onsubmit
Emp_idstartingfrom 1001andemp_name >5 &5 &5 &