Você está na página 1de 2

ADVANCED SOFTWARE ENGINEERING LAB # 02 Lab Teacher: Nida Sadaf Khan Object: Take a string from user and

find the alphabetic, numeric and alpha-numeric words of that string. Perform all the following steps to solve the above problem A) Need Analysis Analyzation of given problem are: Make a program which we have strings. The program divides into three parts J First analyze that how we separate the alphabetic words from the given input string. J Second analyze that how we separate the numerics from the given input string. J Third analyze that how we separate the alphanumeric from the given input string. Take a string for example: I did my BS in 2006, MBA in 2010 and now I am in 1st semester of MS Alphabetic words: I, did, my, BS, in, MBA, in, and, now, I am, in, semester, of, MS Numeric words: 2006, 2010 Alpha-numeric words: 1st b) Need specification Include the prototype of printf/scanf #include<stdio.h>, getch() #include<conio.h> ,for string functions #include<string.h>. Initialize the data type with identifiers that is character type string (Char string, alphabetic, numerics). Now input the string Enter the input string gets takes input string from printf and saved Using while loop (repeated execution statement is execute repeatedly as long as the value of expression remain non-zero i<200 total no of string character which we initialize in string [200] (array). If the input string have null value so it terminate otherwise it compare numerics with string and alphabets with string and as well as increment them self in strings characters and (num or alphabets). c) Algorithm design lDefine total number of string, number and alphabets in the array. lInput string. \\ printf(enter the input string)\\

lgets (string) lusing while loop

\\ store string\\ \\while(i<200)\\

lIf string have a null value so it break and terminated to the while loop otherwise it compare with numbers and alphabets (not complete) d) Implementation (Use C language for coding) #include<stdio.h> #include<conio.h> #include<string.h> void main(void) { clrscr(); char string[200],alphabetic[200],numeric[100]; int i=0,j=0,k=0; printf("\n enter the input string:"); gets(string); while(i<200) { if (string[i]=='\0') break; if(string[i]>=48&&string[i]<=57) { numeric[k]=string[i]; k++; i++; } else { alphabetic[j]=string[i]; j++; i++; } } printf("no of numerics are ="); puts(numeric); printf("no of alphabetic words are ="); puts(alphabetic); getch(); } e) Testing and integration

Você também pode gostar