Vous êtes sur la page 1sur 52

LOVELY PROFESSIONAL UNIVERSITY

ASSIGNMENT OF P & T
INFOSYS CONNECT PROGRAM

AKHIL SHARMA Reg No. 10807224


SEC D1803 BATCH – 2
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.

f. In this statement “;” is extra so on removing it we get - ermination


g. % - garbage value.
h. U

3.

SOL—

a. 5.00
b. 4.5
c. 3.00

4.

SOL—

2004000

DEBUGGING EXERCISE

1 To identify error in program and after correction write output !

SOL –

#include<stdio.h>

#include<conio.h>

#define PI 3.14159
int 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 be used to display

FArea

getch();

return 0;

Output

30,45

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<0)|| (iTemp2<0)
printf(“Sign is negative”);

ANS- The correct statements are as follows :-

If((iTemp<0) || (iTemp2<0))

printf(“Sign is negative”);
3. Find error in each looping segments

SOL—

a. While(iCount!=10);
{
iCount=1;
isum=isum+iNumber;
iCount=iCount+1;
}

ANS - Errors- While should be written in lower case i.e. while and not

While.

Semi-colon is not allowed after while condition.

b. cName=0;
do {
cName=cName+1;
printf(“My name is XXX\n”);
} while(cName=1)

ANS- Errors :- Semi-colon is required at the end to terminate do-while

Loop. Example-

do{

}while();

c. iIndex1 =1; iIndex2 = 0;


for(;iIndex1+iIndex2<10; ++iIndex2);
printf(“Hello\n”);
iIndex1=iIndex + 10
ANS- Errors:- Semi colon is not allowed at the end of for statement

Semi colon is required in the last statement for


termination. Exact code is as follows :-

iIndex1 =1; iIndex2 = 0;


for(;iIndex1+iIndex2<10; ++iIndex2)
printf(“Hello\n”);
iIndex1=iIndex + 10;
d. for(iIndex3=10; iIndex3>0;)

iIndex3=iIndex3-1;

printf(“%f”,iIndex3);

ANS - The above code does not have any error . the output of the

following code will be 0.0000

4. Identify error if any in each case of following initialization

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 and columns cannot

Be initialized in the same square brackets.

e. float fResult[10]=0;

ANS – The above initialization is not correct ,either size should not be

Mentioned or all ten elements should be assigned a value.

5.

SOL-

#include<stdio.h>

#define SIZE 10

int main()

int aiArr[SIZE];

int iSum;

int iIndex;

printf("Enter 10 numbers :-");

for(iIndex=0;iIndex<=SIZE;iIndex++)// inputting 1 extra

value then the size of array

{
scanf("%d",a[i]); // & is not used during input i.e. &a[i]

for(i=0;i<s;i++)

sum=sum+a[i];

printf("\n The sum is %d ",sum);

return 0;

So there were two error in the programs , one is allocating extra

memory during input and second is not using “&” while inputing

the data.

The output of the program depends upon the values inserted by

the user .

6.

SOL-

#include<stdio.h>

#include<conio.h>

int main(int argc , char **argv)


{

double dPrice,dDiscount;

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 not allowed

printf("Sales tax:%2lf%%\n ",dSalesTax) // semicolon is missing

and %% is not allowed

dPriceAfterDiscount=dPrice-((dPrice*dDiscount)/100.0);
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 –
ASSIGNMENT DAY2
Q1.
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
int main()
{
char cname[40];
float ihour_rate,gross_pay,fover_time,ihour_worked
float tax,net_pay;
cout<<"enter the employ name";
cin>>cname;
cout<<"enter the hour rate";
cin>>ihour_rate;
cout<<"enter the hour worked";
cin>>ihour_worked;
if(ihour_worked<=0 || ihour_rate<=5.50)
{
cout<<"you have enter wrong hours or rate";
}
cout<<"enter the overtime ";
cin>>fover_time;
gross_pay=ihour_rate*ihour_worked
+ihour_rate*fover_time;

cout<<"\n gross pay is"<<gross_pay;


cout<<"\ntax pay is";
tax=(gross_pay*30)/100;
cout<<tax;
cout<<"\nnet pay is";
net_pay=gross_pay-tax;
cout<<net_pay;

cout<<"\n*****************************************";
cout<<"\n************salary is********************";
cout<<"\n name of employees:-"<<cname;
cout<<"\n gross pay :"<<gross_pay;
cout<<"\n net pay :"<<net_pay;
getch();
return 0;
}
Q2.
#include<stdio.h>
#include<conio.h>
# 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”);
printf(“Error %d”,error);
}
getch();
}
int fnemployeeNameValid(char name[15])
{
char na[15];
int count=0;
for(i=0;i<15;i++)
{
if(na[i]==isupper[na]||
na[i]==islower[na]||
na[i]== ‘ ’)
{
count++;
}
else
{
count=0;
break;
}
}
return(count);
}
Q3.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
void main()
{
char name[20];
int num=0;
cout<<"enter the name";
cin>>name;

for(int i=0;i<20;i++)
{
if(name[i]!='\0')
{
if(name[i]=='a'||name[i]=='e'||name[i]=='i'||
name[i]=='o'||name[i]=='u')
num=num+1;
}
}
cout<<"vowels used in this strig is: "<<num;
getch();

Q4.
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
void main()
{
char name1[20],name2[20];
cout<<"enter the name 1 and name 2";
cin>>name1>>name2;
int check(char name1[],char name2[]);
int d;
d=check(name1,name2);
cout<<"we have "<<d<<"comman words";
getch();
}
int check(char name1[],char name2[])
{
int num=0;
for(int i=0;i<20;i++)
{
if(name1[i]!=0)
{
if(name1[i]==name2[i])
num=num+1;
}
}
return num;
}

Q5.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
long 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);
}
Q6.
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<iostream.h>
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<<cmonth[0];
cout<<cmonth[1];
cout<<"\n enter the date";
cin>>dateofbirth.day;
cout<<"\n entr the month";
cin>>dateofbirth.month;
cout<<"\n enter the year";
cin>>dateofbirth.year;
cout<<"your date of birth
is"<<dateofbirth.day<<"-"<<cmonth[dateofbirth.month-
1]<<"-"<<dateofbirth.year;
getch();
}

Q7.
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<iostream.h>
struct dob
{
short int day;
short int month;
short int year;
}dateofbirth;

void main()
{
int d;
char cmonth[12]
[12]={"january","february","march","april","may","june","
july","august","sep","oct","nov","dec"};
cout<<"\n enter the date";
cin>>dateofbirth.day;
cout<<"\n entr the month";
cin>>dateofbirth.month;
cout<<"\n enter the year";
cin>>dateofbirth.year;
cout<<"your date of birth
is"<<dateofbirth.day<<"-"<<cmonth[dateofbirth.month-
1]<<"-"<<dateofbirth.year;
int valid(struct dob dateofbirth);
d=valid(dateofbirth);
if(d==0)
cout<<"invalid date";
else
cout<<"valid date";
getch();
}
int valid(struct dob dateofbirth)
{
if(dateofbirth.month>=1 && dateofbirth.month<=12)
{
if(dateofbirth.year%400==0)
{
if(dateofbirth.month==2)
{
if(dateofbirth.day>=1 && dateofbirth.day<=29)
cout<<"\n valid date of birth";
}
else
cout<<"invalid date";
}
else if(dateofbirth.day>=1 && dateofbirth.day<=31)
cout<<"valid date";
else
cout<<"invalid date";
}
}
else if(dateofbirth.year%100!=0)
{
if(dateofbirth.year%4==0)
{
if(dateofbirth.month==2)
{
if(dateofbirth.day>=1 &&
dateofbirth.day<=29)
{
return 1;
}
else
return 0;
}
else
{
if(dateofbirth.day>=1 && dateofbirth.day<=31)
return 1;
else
return 0;
}
}
else
{
if(dateofbirth.day>=1 && dateofbirth.day<=31)
return 1;
else
return 0;
}
}
else
if(dateofbirth.day>=1 && dateofbirth.day<=31)
return 1;
else
return 0;
}
}
else
return 0;
}
Q8.
#include<stdio.h>
void 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 THE ARRAY…:”);
for(i=1; i<=N; i++)
{
gotoxy(25, 11+i);
scanf(“\n\t\t%d”, &A[i]);
}
for(i=1; i<=N-1; i++)
for(j=i+1; j<=N;j++)
if(A[i]>A[j])
{
Temp = A[i];
A[i] = A[j];
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.
#include<stdio.h>
void 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. OF
EMPLOYES...:");
for(i=0; i<N; i++)
{
gotoxy(25,11+i);
scanf("\n\t\t%d", &A[i]);
}
for(i=1; i<N; i++)
{
Temp = A[i];
j = i-1;
while(Temp<A[j] && j>=0)
{
A[j+1] = A[j];
j = j-1;
}
A[j+1] = Temp;
}
printf("\n\tTHE ASCENDING ORDER LIST IS...:\n");
for(i=0; i<N; i++)
printf("\n\t\t\t%d", A[i]);
getch();
}

Q10
#include<stdio.h>

#include<conio.h>

void main()

int a[50],i,j,low,mid,ele,high;

printf(“Enter no of emp : - “);

scanf(“%d”,&n);

print(“Enter emp ids :- “)

for(i=0;i<n;i++)

scanf(“%d”,a[i]);

for(i=0;i<n;i++)

{
for(j=1;j<n;j++)

If(a[i]>a[j]))

Temp=a[i];

a[i]=a[j];

a[j]=a[i];

printf(“enter the id to be searched : - “);

scanf(“%d”,&ele);

low= 1

high=n

do

mid=(High+low)/2
if(a[mid]<S)

low= mid+1;

else

high=mid-1;

}while((low<=mid))||a[mid]==ele);

if(a[mid]==ele)

Printf(“element found at %d”,mid);

else

printf(“Element not in the list “);

getch();

Q 11
#include<stdio.h>
#include<conio.h>
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<n;i++)
{
printf(“Enter marks of maths,physics and
chemistry”);
scanf(“%d%d%d”,&m1,&m2,&m3);
total=m1+m2+m3;
t1=m1+m2;
if((m1>=60&& m2>=50&& m3>=40))||total>200||
t1>=150)
adm++;
}
printf(“No of students passed 4 admission are :-
%d”,adm);
getch();
}
Q 12
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
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 u
want to extract the data”)
scanf(“%d%d”,&l,&m);
for(int i=l;i<=m;i++)
{
printf(“%c”,ch);
}
getch( ); }
Q13
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<iostream.h>
struct cricket
{
char name;
char tname;
int avg;
}c1;

void main()
{
int a[50];
for(i=0; i<50;i++)
{
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<50;i++)
{
printf(“ name of player : “);
puts(c1.name);
printf(“name of team : “);
puts(c1.tname);
printf(“avg of player : “);
printf(“%d”,avg);
}
getch();
}
Q14
#include<conio.h>
#include<stdio.h>
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];
char d;
int Count;
for(i=0;i<20;i++)
{
If(d==na[i])
Count++;
}
Printf(“Occurance of %c is %d times”,d,Count);
}
void fnDel(char name[20],char c)
{
char na[20];
char d;
for(i=0;i<20;i++)
{
If(d==na[i])
na[i+1]=na[i];
}
Printf(“After deletion string is %c ”,na);
}
Q15
#include<conio.h>
#include<stdio.h>
void 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”);
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

ASSIGNMENT 1 : Identify test cases using Boundary Value analysis

SOL –

Float fnComputeRateofInterest (int iAmount)

If(amount>=5000 && amount<=10000)

Rate=0.05;

else if(amount>=10001 && amount<=15000)

Rate=0.07;

else if(amount>=15001 && amount<=20000)

Rate=0.09;

}
else if(amount>=20001 && amount<=25000)

Rate=0.11;

else if(amount>=25001 && amount<=30000)

Rate=0.15;

else

printf(“Error in input”);

S. Test case Test Pre Condition Expect Reference


No name Procedure ed to
. Result detailed
design
1. fnCompute Call Amount>5000 Error in fnComput
Rateof fnCompute and amount< Input eRateof
Interest_4000 RateofInterest 30000 -ve test Interest
with amount =
4000
2. fnCompute Call Amount>5000 Rate = fnComput
Rateof fnCompute and amount< 5% eRateof
Interest_9000 RateofInterest 30000 Interest
with amount =
9000
3. fnCompute Call Amount>5000 Rate = fnComput
Rateof fnCompute and amount< 7% eRateof
Interest_ RateofInterest 30000 Interest
12000 with amount =
12000
4. fnCompute Call Amount>5000 Rate = fnComput
Rateof fnCompute and amount< 9% eRateof
Interest_ RateofInterest 30000 Interest
19000 with amount =
19000
5. fnCompute Call Amount>5000 Rate = fnComput
Rateof fnCompute and amount< 11% eRateof
Interest_ RateofInterest 30000 Interest
23000 with amount =
23000
6. fnCompute Call Amount>5000 Rate = fnComput
Rateof fnComputeRat and amount< 15% eRateof
Interest_ eofInterest 30000 Interest
29000 with amount =
29000
7. fnCompute Call Amount>5000 Error in fnComput
Rateof fnComputeRat and amount< Input eRateof
Interest_ eofInterest 30000 -ve test Interest
32000 with amount =
32000

ASSIGNMENT 2 : Identify test cases using Logic Coverage

SOL –

S. Test case Test Pre Condition Expecte Referenc


No name Procedure d Result e to
. detailed
design
1. OnLinebal Both the fields Pin_no=4 digit Error in OnLine
Enquiry_pin_ are filled and _no starting Input bal
no=3 digit click on submit from 1001 and -ve test Enquiry_
&10_digit_acc acc_no = 10
_no digit_no
2. OnLinebal Both the fields Pin_no=4 digit Error in OnLine
Enquiry_pin_ are filled and _no starting Input bal
no=4 digit & click on submit from 1001 and -ve test Enquiry_
9_digit_acc_ acc_no = 10
no digit_no
3. OnLinebal Both the fields Pin_no=4 digit Display OnLine
Enquiry_pin_ are filled and _no starting Balance bal
no=4 digit & click on submit from 1001 and amount Enquiry_
10_digit_acc_ acc_no = 10
no digit_no

4. OnLinebal Both the fields Pin_no=4 digit Error in OnLine


Enquiry_pin_ are filled and _no starting input bal
no=0200 & 10 click on submit from 1001 and -ve test Enquiry_
_ digit acc_no = 10
_acc_no digit_no
5. OnLinebal Both the fields Pin_no=4 digit Display OnLine
Enquiry_pin_ are filled and _no starting Balance bal
no=1200 & 10 click on submit from 1001 and amount Enquiry_
_ digit _ acc _ acc_no = 10
no digit_no
6. OnLinebal Both the fields Pin_no=4 digit Display OnLine
Enquiry_pin_ are filled and _no starting Balance bal
no=2200 & 10 click on submit from 1001 and amount Enquiry_
_ digit _ acc _ acc_no = 10
no digit_no
7. OnLinebal Both the fields Pin_no=4 digit Error in OnLine
Enquiry_pin_ are filled and _no starting input bal
no=3200 & 9 _ click on submit from 1001 and -ve test Enquiry_
digit _ acc _ acc_no = 10
no digit_no

ASSIGNMENT 3 : Identify test cases using Logic Coverage


SOL –

S. Test case Test Pre Expected Referenc


No name Procedure Condition Result e to
. detailed
design
1. Emp_tel_no_ Both the fields Emp_id Print Error Emp_tel
All blank are filled and starting in _no.
click on submit from 1001 Input
and And ask
emp_name user to
>5 &<30 no add
spl symbols atleast 1
entity
3. Emp_tel_no_ Type invalid id Emp_id Emp_tel_ Emp_tel
Emp_id_fail and click on starting no must _no.
submit from 1001 fetch 0
and record
emp_name and
>5 &< 30 no display
spl symbols record not
found

4. Emp_tel_no_ Type name Emp_id Emp_tel_ Emp_tel


Name_full and click on starting no_ must _no.
submit from 1001 fetch only
and 1 entry of
emp_name person
>5 &< 30 no with that
spl symbols name

5. Emp_tel_no_ Invalid name Emp_id Print Error Emp_tel


Name_with_ and click on starting in _no.
Special_ submit from 1001 Input
characters and And ask
emp_name user to
>5 &< 30 no add name
spl symbols without
special
symbols

DAY 4 ASSIGNMENT

CODE REVIEW ASSIGNMENT


Code Review Assignment Code Review Assignme

1. /
*************************************************************
******************
2. File Name: bookInventory.c
3. Description: Simple program which calculates area of a circle.
4. Author: ABC
5. Date: 02-Dec-2008
6. *************************************************************
******************/
7. #include <stdio.h>
8. #include <string.h>
9. /* Business Logic related error and success codes */
10.#define SUCCESS 0
11.#define ERROR_INSUFFICIENT_BALANCE -1
12./
*************************************************************
******************
13.Structure: book
14.Description: Stores book details*
15.Member Variables:
16.acAuthor - Name of the author (Range: 20 characters)
17.acTitle - Title of the book (Range: 30 characters)
18.fPrice - Price of the book
19.*************************************************************
******************/
20.struct book {
21.char acAuthor[20];
22.char acTitle[30];
23.float fPrice;
24.struct
25.{
26.char acMonth[10];
27.int iYear;
28.} date;
29.char acPublisher[10];
30.int iQuantity;
31.};
32./* Forward declarations of functions*/
33.int fnLook_Up (struct book sBook[], char[], char[],int);
34.void fnGetString(char []);
35.int atoi(char[])
36./
*************************************************************
******************
37.Function: main()
38.Description: A code to search for a book in the Inventory.
39.When a customer requires a book, that book is searched in the library.
40.if the book is available, then the number of copies is requested from
41.the user and the total cost is displayed. If the requested number of copies
42.are not available, then appropriate error message is displayed.
43.Input Parameters:
44.int argc - Number of command line arguments
45.char **argv The command line arguments passed
46.Returns: 0 on success to the operating system
47.*************************************************************
******************/
48.int main (int argc, char** argv){
49./* Declare an instance of bookdetails */
50.char title[30], author[20];
51.int iIndex, iNo_of_Books;
52.int iquantity;
53.char acResponse[10], quantity[10];
54.static struct book sbook[] = {
55.{"Ritche", "C Language", 90.00, "May", 1977, "PHI",10},
56.{"Herbert", "Programming in Java",150.00, "July",1983,"Hayden", 5},
57.{"B V Kumar","Web Services",180.00,"january",1984,"TMH",10},
58.{"Sierra Bates", "SCJP", 250,"October",1995, "DreamTech", 0}
59.};
60.iNo_of_Books = sizeof(sbook) / sizeof(struct book);
61.do
62.{
63.printf("Enter title and author name \n");
64.printf("\n Title: ");
65.fnGetString(title);
66.printf("Author: ");
67.fnGetString(author);
68.iIndex = fnLook_Up(sbook, title,author,iNo_of_Books);
69.if (iIndex != -1) /* Book found */
70.{
71.printf("\n%s%s%.2f %s%d%s\n\n",
72.sbook[iIndex].acAuthor,
73.sbook[iIndex].acTitle,
74.sbook[iIndex].fPrice,
75.sbook[iIndex].date.acMonth,
76.sbook[iIndex].date.iYear,
77.sbook[iIndex].acPublisher );
78. printf("Enter number of copies:");
79.fnGetString(quantity);
80.iquantity = atoi(quantity);
81.if (iquantity < sbook[iIndex].iQuantity)
82.printf("Cost of %d copies = %.2f\n", iquantity,
83.sbook[iIndex].fPrice * iquantity);
84.else
85.printf("\nRequired copies not in stock\n\n");
86. }
87.else
88.printf("\nBook not in list\n\n");
89.printf("\nDo you want ay other book? (YES/NO):");
90.fnGetString(acResponse);
91. }
92.while(acResponse[0] ='Y' || acResponse[0] == 'y');
93.printf("\n\nThank you. Good Bye\n");
94.return 0;
95.}
96./
*************************************************************
******************
97.Function: fnGetString
98.Description: Gets the character input from the User
99.Input Parameters:
100. char string[] - String which has to be input
101. *
102. Returns: nothing
103. ********************************************************
***********************/
104. void fnGetString (char acstring[]) {
105. char c;
106. int i = 0;
107. do
108. {
109. c = getchar();
110. acstring[i++] = c;
111. }
112. while (c != '\n');
113. acstring[i-1] = '\0';
114. }
115. /
*************************************************************
******************
116. Function: fnLook_Up
117. Description: A function which searches for the book in the list
118. Input Parameters:
119. book sbook - A variable is declared as type struct book
120. char actitle[] - which receives the title
121. char acauthor[] - which receives the author name
122. int iTotal_No_Of_Books - which receives the total number of books in
the list
123. Returns:
124. Serial Number on success,
125. -1 when the book is not found
126. *
127. ********************************************************
***********************/
128. int fnLook_Up(struct book sbook[], char actitle[], char acauthor[], int
iTotal_No_Of_Books) {
129. /* Declaration for account number and amount */
130. int i;
131. for (i=0; i < iTotal_No_Of_Books; i++)
132. if (strcmp(actitle, sbook[i].acTitle) == 0 ||
133. strcmp(acauthor, sbook[i].acAuthor) == 0)
134. return (i); /* book found */
135. return(-1); /* book not found */
136. }

S NO LINE COMMENT SUGGESTION


1 3 description of c file does Write a proper description
not reflect what code is
meant for code
2 9 Comment not according Write proper comment
to the program
3 10 Variable not according to Declare proper variable
the code of program according to the need
4 11 Variable not according to Declare proper variable
the code of program according to the need
5 20 Indentation not Proper indentation should be
mentioned while defining maintained
structure
6 22 Both author and title Declaration of same variable
name declaration can be can be done in same line
assigned in same line
7 23 Structure book not Struct should be closed after
closed after declaration use
8 23 Object not initialized of Object should be initialized of
the structure book structure to access it members
9 29 Incorrect declaration of Proper declaration should be
acPublisher provided
10 30 Incorrect declaration of Proper declaration should be
iQuantity provided
11 35 Incorrect function Proper declaration should be
declaration provided
12 48 Indentation not Proper indentation should be
maintained. maintained
13 52 Iquantity can also be Declaration of same variable
declared in same line as can be done in same line
index and no of books is
declared.
14 54 Indentation not Proper indentation should be
maintained. maintained
15 54 No need to declare As only static function can
function as static access these data.
16 63 scanf statement missing Scanf should come just below
for title and author name printf for easy understanding
after printf
17 71 Extra parameter for Equal no of parameter should
printing . be assigned
18 79 Quantity is of int type Proper calling of variable
and is being called by should be done
string
19 81 Sbook not initialized Variable should be initialized
before using
20 84 Misplaced else Else if should be used
21 86 } – not required. Not allowed in between if else
if ladder
22 92 While statement should do
be written in upper line. {
}while(); - syntax should be
followed
23 95 getch() should be used to Getch() should be used for
display proper result displaying result
24 100 Wrong description Correct name should be used
provided as wrong name
is used.
25 101 line should not be left No empty spaces allowed in
empty while function headers
description header
26 106 Indentation not Proper indentation should be
maintained maintained
27 109 printf statement missing Proper statements should be
provided
28 104 Indentation not Proper indentation should be
maintained maintained
29 126 Empty lines not allowed No empty spaces allowed in
in header headers
30 128 Indentation not Proper indentation should be
maintained maintained
31 130 Declaration can be done for(int i;i<0;i++) is valid so can
within the for loop be initialized in this manner
also
32 131 { - starting braces of for for(…………….)
loop missing {
statement
}
Following format should be
followed.
33 133 And statement should Comparison statement should
come together come together.

Vous aimerez peut-être aussi