Académique Documents
Professionnel Documents
Culture Documents
ASSIGNMENT OF P & T
INFOSYS CONNECT PROGRAM
DAY 1 ASSIGNMENT
1.
SOL –
a. 20.
b. 10.
2.
SOL—
3.
SOL—
a. 5.00
b. 4.5
c. 3.00
4.
SOL—
2004000
DEBUGGING EXERCISE
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;
FArea
getch();
return 0;
Output
30,45
SOL—
printf(“ ”);
b. If(iCode>1);
iValue= iValue2+iValue3
else
iValue1=0
If(iCode>1)
iValue= iValue2+iValue3;
else
iValue1=0;
c. If(iTemp<0)|| (iTemp2<0)
printf(“Sign is negative”);
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.
b. cName=0;
do {
cName=cName+1;
printf(“My name is XXX\n”);
} while(cName=1)
Loop. Example-
do{
}while();
iIndex3=iIndex3-1;
printf(“%f”,iIndex3);
ANS - The above code does not have any error . the output of the
SOL-
a. int iNumber[]={0,0,0,0,0};
c. char cWord[]={‘A’,’R’,’R’,’A’,’Y’};
ANS – The above initialization is correct.
ANS – The above initialization is wrong , the rows and columns cannot
e. float fResult[10]=0;
ANS – The above initialization is not correct ,either size should not be
5.
SOL-
#include<stdio.h>
#define SIZE 10
int main()
int aiArr[SIZE];
int iSum;
int iIndex;
{
scanf("%d",a[i]); // & is not used during input i.e. &a[i]
for(i=0;i<s;i++)
sum=sum+a[i];
return 0;
memory during input and second is not using “&” while inputing
the data.
the user .
6.
SOL-
#include<stdio.h>
#include<conio.h>
double dPrice,dDiscount;
double dPriceAfterDiscount,dNetPrice;
scanf("%lf",&dPrice);
fflush(stdin);
fflush(stdin);
if(dPrice>500.0)
dDiscount=25.0;
dDiscount=15.0;
dPriceAfterDiscount=dPrice-((dPrice*dDiscount)/100.0);
dNetPrice=dPriceAfterDiscount+((dPriceAfterDiscount*dSalesTax)
getch();
return 0;
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*****************************************";
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;
scanf(“%d”,&n);
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];
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)
else
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
SOL –
Rate=0.05;
Rate=0.07;
Rate=0.09;
}
else if(amount>=20001 && amount<=25000)
Rate=0.11;
Rate=0.15;
else
printf(“Error in input”);
SOL –
DAY 4 ASSIGNMENT
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. }