Software Engineering (Pr) IT-313 By Rishita Jaggi 1140213 B.Tech. Third Year IT-3 Submitted to Course Coordinator: Dr. BB Gupta DEPARTMENT OF COMPUTER ENGINEERING NATIONAL INSTITUTE OF TECHNOLOGY KURUKSHETRA-136119, HARYANA (INDIA) July-Dec, 2016 INDEX Serial No Experiment 1 To identify the role of the software in today’s world across a few significant domains related to day to day life. 2 To identify the problem related to software crisis for a given scenario. 3 To identify the suitable software development model for the given scenario. 4 To identify the various requirement activities viz. Elicitation, Analysis, Specification and Verification for the given scenarios. 5 To identify the various elicitation techniques and their usage for the banking case study. 6 To Classify the requirement into functional and nonfunctional requirements. 7 Identify the elements in software Requirements Specification document. 8 Identify the design principle that is being violated in relation to the given scenario. 9 To identify the usage of stubs or drivers in the context of an integration testing scenario. 10 Identify the different types of performance testing. 11 To identify the usage of regression testing. P-1 Implement Halstead’s equation to compute various science metrics like volume etc., language level, estimated program length, effort and time in a program. P-2 Compute average number of live variables per statement in a program. P-3 To find the average life of variables in a program. P-4 To perform boundary value analysis of a program. P-5 Compute McCabe’s cyclometric complexity of a program. Signature EXPERIMENT 1 (Role of Software) Objective: To identify the role of the software in today’s world across a few significant domains related to day to day life. Background: Software has made the world a global village today. The impact of software spans across almost all aspect of human life. All organizations, Institutions and companies are leveraging the potentials of software in automating the critical functions and eliminating manual interventions. Software is also a predominant are for trade and export especially for the countries like India. Domains like health care, Airlines , financial Services, Insurance , retails, Education, and many more have exploited software and still there a lot of the scope for software to create impact and add values in multiple dimensions. Problem description: In the context of this background, identify the areas (or application or systems) how software has been leveraged extensively in the following domains, 1. Health Care: Hospital Management softwares Image processing – For example, X-Rays, Ultrasound. iCare 2. Airlines: Airways Management softwares GDS -A Global Distribution System (GDS) is a network operated by a company that enables automated transactions between travel service providers (mainly airlines, hotels and car rental companies) and travel agencies. 3. Education: E-learning. Online Courses with various websites like Coursera, edX, AcademicEarth etc. Technical softwares – For example: MATLAB, emu8086. Database storing softwares like MySQL,SQLite. 4. Retail: E-commerce softwares. Amazon, Filpkart,Snapdeal are the examples. 5. Banking: E-banking application softwares like EBANQ. FINACLE : Universal banking software. EXPERIMENT 2 (Software Crisis) Objective: To identify the problem related to software crisis for a given scenario. Background: In the early years of computers applications, the focus of the development and innovation were on hardware. Software was largely views as an afterthought. Computer Programming was an art. Programmers did not follow any disciplined or formalized approaches. This way of doing things was adequate for a while, until the sophisticated of computer applications outgrow. Software soon took over and more functions which were done manually. A software houses begin to develop for widespread distribution. Software development projects produced thousands of source program statement. With the increase in the size and complexity of the software, following situation resulted is collectively termed as software crisis. 1. Time Slippage 2. Cost Slippage 3. Failure at customer Site 4. Intractable Error after delivery Problem description: In the context of this background, for each of the scenario mentioned below, identify the most appropriate problem related to software crisis and mention the same in the table provided. Scenario A Railways reservation software was delivered to the customer and was installed in one of the metro station at 12.00 AM (mid-night) as per the plan. The system worked quite fine till the next day 12.00 PM (noon). The system crashed at 12.00 PM and the railways authorities could not continue using software for reservation till 02.00 M. It took two hours to fix the defect in the software in the software. Scenario B A polar satellite launch vehicle was scheduled for the launch on August 15th. The auto-pilot of the rocket to be delivered for integration of the rocket on may 15 th. The design and development of the software for the auto-pilot more effort because of which the autopilot was delivered for the integration on June 15th (delayed by a month). The rocket was launched on Sep 15th (delayed by a month). Scenario C Software for financial systems was delivered to the customer. Customer informed the development team about a mal-function in the system. As the software was huge and complex, the development team could not identify the defect in the software. Scenario D Due to the defect in the software for the baggage handling system. There was also of & 2M of revenues for the airport authorities. Solution: Scenario Situation A Failure at customer site. B Time slippage C Intractable Error after delivery D Cost Slippage EXPERIMENT 3 (Software Development Model) Objective: To identify the suitable software development model for the given scenario. Background: “ABC” is a new enterprise recently started by a few young entrepreneurs, intended to develop robotic systems using IT based solutions. “TENZ” is a well-established automobile manufacturing plant, interested in automating some of the operations of the plant. As first step towards automation, TENZ has decided to deploy a robotic arm to pick and place large number of bolts from one tray of a conveyer belt to another tray of a different conveyer belt, moving one bolt at a time. TENZ has asked ABC for demonstration the robotic arm for the said purpose as a proof of concept. This is the first project being executed by ABC. TENZ would like to have a first experience of the robotic arm before signing the MOU (Memorandum of Understanding) with ABC. After MOU sign-off, TENZ would provide the complete set of requirement of the robot. Problem description: Identify the most appropriate SDLC model for this scenario. Solution: For the given scenario, taking in light all the initial problems, it can be concluded that the appropriate model for the development of the robotic system is “PROTOTYPE MODEL”. Prototype model is one of the evolutionary models which is used when the requirements are not clear and complete in the initial stage of software development. It is used when the final product is to be delivered only once with full functionality with completion of small functionalities in each continuing steps. According to the prototype model, first the simple prototype is delivered to the customers, who are then evaluated and final SRS is made by the customers. Thus, after the evaluation of the prototype all the requirements are finalized and then only the real development of the software is started. Given scenario have similar conditions with the robotic arm as the prototype. After evaluation of the arm by TENZ the final requirements are framed and MOU is signed off. Then, the ABC team will work with development of robotic system. Thus, the appropriate model is prototype model. EXPERIMENT 4 Objective: To identify the various requirement activities viz. Elicitation, Analysis, Specification and Verification for the given scenarios. Requirement engineering produces a specification of what a system should do. The intention of requirement engineering is to provide a clear definition of requirement of the systems. This phase is a very important phase because, if the customer requirements are not clearly understood, the ambiguity can get into the other phase of the development. To avoid such issues, requirement has to be elicited using the right elicitation techniques, to be analysed effectively, specified clearly and verified thoroughly. All activities are collectively termed as requirement development activities. Scenario Requirement Development Activities a Requirement Elicitation As here the Developer has prepared a questionnaire to understand the exact requirements of the system by getting feedback from the client or users. Thus, here the developer understands the user’s requirements. b Requirement Specification Here, the Developer is preparing a formal document, also known as Software Requirement and Specification Document (SRS), which defines the features of the Software. c Requirement Analysis The requirements are analysed in order to identify inconsistencies, defects, omissions etc. The requirements are described in terms of relationships and also resolve conflicts, if any. d Requirement Classification Developers assign a class or label to the group of requirements. e Requirement Elicitation Here the developer is sent to the client to observe the business case to collect typical user’s requirements and to understand them. f Requirement Verification In this, the developers verify the requirements and ensure that requirements collected should not be missing, vague or unclear. g Requirement Elicitation Developers arrange a meeting with the customer to understand their expectations from the Software. h Requirement Elicitation As here the Developer has prepared a questionnaire to understand the exact requirements of the system by getting feedback from the client or users. Thus, here the developer understands the user’s requirements. EXPERIMENT 5 Objective: To identify the various elicitation techniques and their usage for the banking case study. Requirement elicitation is the process of seeking, discovering, acquiring and elaborating requirement. This includes learning and understanding the needs of the users. This activity is communication centric and iterative in the nature. The techniques used here are the important to get stack holder consensus on the requirements. Scenario Interrogative conversation with Managers, Cashiers, Clerks and other Staff for arriving at the requirement for automating transactions. Formal and planned requirement discussion in a Conference to room conducted among managers of diversified branched facilitate by anchor. Requirement Elicitation Technique Interview In this, Requirement Engineers conduct an interview with the clients to understand the requirements. Workshops Organization may conduct workshops among various stakeholders by querying about their expectation and requirements from the upcoming system. Survey form circulated among the users Questionnaire (account holders) who visit the bank, to ease A document with pre-defined set of their interactions with bank objective questions and respective options is handed over to all stakeholders to answer, which are collected and compiled. Analysis for understanding mode of Task Analysis transactions- Checks, Cash, DD, MT, Gold, Team of engineers and developers may etc. analyze the operation for which the new system is required. If the client already has some software to perform certain operation, it is studied and requirements of proposed system are collected. Ethnographers deployed for understanding Observation the users interactions with bank officials. Team of experts visit the client’s organization or workplace. They observe the actual working of the existing installed systems. UI design of e-banking portal, ATM, Prototyping Computer Systems Prototyping is building user interface without adding detail functionality for user to interpret the features of intended software product. It helps giving better idea of requirements. Understanding the process involved in each Scenario identification transaction like withdraw, deposit, fund In this, the developers identify and transfer etc. understand the complete scenario of the system. EXPERIMENT 6 (Requirement classification) AIM: To classify requirements into functional and non functional requirements. THEORY: Functional requirements specify the software functionality that the developer must build into the product to enable users to accomplish their tasks. Non functional requirements are related to the system as whole rather than to individual functions. Failure to meet a functional requirement degrades the system while failure to meet a non functional requirement may make the whole system unusable. SCENARIO: SR .NO 1. 2. 3. 4. Requirement description Requirement type ATM machine shall validate PIN of the user during login along with biometric verification Peak transaction volume-20000 calls in a busy hour,average duration 20 secs, grade of services 99.98%. Brake system shall sound the alarm for 10 sec at frequency of 100H when the brake is applied. Mean time to failure(MTTF)-There should be no more than three Severity -1 outage per month Functional Non functional Functional Non functional EXPERIMENT 7 (Requirements) AIM: Identify the elements of Software Requirement Specification document. THEORY: The output of requirement analysis is software requirement specification document. It should clearly specify what the system should do. A typical SRS consists of system overview, objectives of proposed system such that it is proven significant over the existing system, analysis of functional and non functional requirements etc. PROBLEM OVERVIEW: AS, a giant books franchise has approached IT company ABC Ltd. to automate its processes and shift them online. ABC Ltd agrees to take on the project and, both the companies sits down and strikes a deal. After detailed discussion ABC Ltd decides to follow water fall model for development of the project. The concerned team at ABC designed and developed the SRS. Which of these are expected to be present in the SRS? ELEMENT PRESENT OR NOT? System Overview Yes, it is required and it comes under the Introduction. Class Diagram Not mandatory. Source Code Not required. Use Cases Yes, it is required and it comes under Overall Description. Flow Charts for algorithms realizing the functionality of the system Not required as it comes under designing part. Code review Comments Not required as it comes under designing part. Test results Test results of existing system are required and it comes under System Overview. Yes, it is required and it comes under System Overview. Yes, it comes under Nonfunctional requirements. Yes, it is required and it comes under Functional requirements. The Difference in the scope of the current system to be proposed system. Non-Functional requirements Features of new portal to be developed EXPERIMENT 8 (Software Design Principles) AIM: To identify the design principle that is being violated in the given scenarios. THEORY: A good object oriented design not only meets the specified requirements but also addresses implicit requirements. There are five design principles which address most of the implicit requirements: Software Design Principles 1. Abstraction: Focus on solving a problem by considering the relevant details and ignoring the irrelevant. 2. Encapsulation: Wrapping the internal details, thereby making these details inaccessible. Encapsulation separates interface and implementation, specifying only the public interface to the clients, hiding the details of implementation. 3. Decomposition and Modularization: Dividing the problem into smaller, independent, interactive subtasks for placing different functionalities in different components 4. Coupling & Cohesion: Coupling is the degree to which modules are dependent on each other. Cohesion is the degree to which a module has a single, well defined task or responsibility. A good design is one with loose coupling and strong cohesion. 5. Sufficiency, Completeness and Primitiveness: Design should ensure the completeness and sufficiency with respect to the given specifications in a very simple way as possible. Problem: Identify the principle being violated in the given scenarios. SR. NO. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. SCENARIO Important information of a module is directly accessible by other modules Too many global variables in the program after implementing the design Code breaks in unexpected places Unfulfilled requirements in the code after the design has been implemented Cyclic dependency among classes Huge class doing too many unrelated operations Several un-related functionalities/tasks are carried out by a single module All data of all classes in public Design resulting in spaghetti code An algorithm documented as part of design is not understandable by the programmers PRINCIPLE VIOLATED Encapsulation Coupling Abstraction, Primitiveness Sufficiency, completeness Coupling Decomposition, modularisation Cohesion Encapsulation Primitiveness, modularisation, decomposition Primitiveness EXPERIMENT 9 (Integration testing) AIM: To identify the usage of stubs or drivers in the context of an integration testing scenario. THEORY: Integration testing is carried out after the completion of unit testing and before the software is delivered for system testing. In top down integration testing, dummy stubs are required. Similarly in bottom up testing, dummy drivers are required for top level modules. PROBLEM DESCRIPTION: Consider the scenario of development of software for Travel, Management System (TMS) is in progress. The TMS software has 3 major modules namely Ticket_Booking_Module, Hotel_Booking_Module and Taxi_Booking_Module. The Ticket_Booking_Module has 3 sub modules namely Enquiry_Module, Booking_Module and Update_Module. The enquiry module uses Date_Validation_Unit, Ticket_Validation_Unit and Place_Validation_Unit. In the context of the given scenario, identify the usage of stub or driver for the following situations. SITUATIONS: 1: Except the Ticket_validation_Unit, the coding and unit testing of all other modules, sub modules and units of TMS are completed. The top-down integration is in progress for the TMS software. To carry out the integration testing, which among the following is necessary? A Stub for Ticket_Validation_Unit A Driver For Ticket_Validation_Unit A Stub for Enquiry_Module A Driver for Enquiry_Module A Stub For Ticket_Booking_Module A Driver For Ticket_Booking_Module ANS: Stub for Ticket_Validation_Unit 2: The coding and unit testing of all the module, sub modules and units of TMS are completed except the Update_Module (coding and testing for Edit_Module, Cancel_Module and View_Module are also completed). The bottom-up integration is to be started for the TMS software. Mention any stub or driver needed to carry out the integration testing? ANS: Driver for update module. 3: Except the Taxi_Booking_Module, the coding and unit testing of all other modules, sub modules and units of TMS are completed. The top-down integration is to be started for the TMS software. Mention any stub or driver needed to carry out the integration testing? ANS: Stub for taxi booking module. EXPERIMENT 10 (Performance Testing) AIM: Identify the different types of performance testing THEORY: Performance testing tests the non-functional requirements of the system. The different types of performance testing are load testing, stress testing, endurance testing and spike testing. PROBLEM DESCRIPTION: Identify the type of performance testing for the following: SR.NO. 1. 2. 3. 4. SCENARIO TYPE INTEGRATION TESTING A space craft is expected to function for Endurance testing nearly 8 years in space. The orbit control system of the spacecraft is a real-time embedded system which is to be tested before the launch .to ensure that it is capable of working for 8 years in the space. GEC uses an automated tool for conducting Load testing objective type test for the trainees. At a time, a maximum of 2000 trainees are expected to take the test. Before the tool is deployed, testing of the tool was carried out to ensure that it is capable of supporting 2000 simultaneous users. A university uses its web based portal for Spike testing publishing the results of the students. When the results of an examination were announced on the website recently on a pre-planned date, the web site crashed. During unexpected terrorist attack, one of the Spike testing popular websites crashed as many people logged into the web-site in a short span of time to know the consequences of terrorist attack and for immediate guidelines from the security personnel. After analyzing the situation, the maintenance team of that website came to know that it was the consequences of unexpected load on the system which had never happened previously. OF EXPERIMENT 11 (Regression Testing) Objective- To identify the usage of regression testing. Background Enhancements are introduction of new features to the software and might be released in different versions. Whenever a version is released, regression testing should be done on the system to ensure that the existing features have not been disturbed. Problem Description Consider the scenario of development of software for Travel Management System (TMS) discussed in previous assignment. TMS has been developed by Infosys and released to its customer Advance Travel Solutions Ltd. (ATSL). Integration testing, system testing and acceptance testing were carried out before releasing the final build to the customer. However, as per the customer feedback during the first month of usage of the software, some minor changes are required in the Enquiry Module of the TMS. The customer has approached Infosys with the minor changes for upgrading the software. The development team of Infosys has incorporated. Those changes, and delivered the software to testing team to test the upgraded software. Which among the following statement is true? 1. Since minor changes are there, integration of the Enquiry Module and quick system testing on Enquiry module should be done. Ans-True 2. The incorporation of minor changes would have introduced new bugs into other modules, so regression testing should be carried out. Ans-True 3. Since the acceptance testing is already carried out, it is enough if the team performs sanity testing on the Enquire module. Ans-True 4. No need of testing any module. Ans-False PROGRAM 1 Objective: Implement Halstead’s equation to compute various science metrics like volume etc., language level, estimated program length, effort and time in a program. Solution: #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> typedef struct { short int plus; short int minus; short int multiply; short int modulo; short int division; short int and; short int or; short int not; }operator; typedef struct{ short int number_of_int; short int number_of_float; short int number_of_char; short int number_of_file; }operand; operator op; operand opd; int n1=0,N1=0,n2=0,N2=0; void find_operators(char *filename) { FILE *fs; char ch; fs=fopen(filename,"r+"); if(fs==NULL) { printf("File Not Found"); exit(EXIT_FAILURE); } while(1) { ch=fgetc(fs); if(ch==EOF) break; switch(ch) { case '+': op.plus++; break; case '-': op.minus++; break; case '*': op.multiply++; break; case '%': op.modulo++; break; case '/': op.division++; break; case '&': op.and++; break; case '|': op.or++; break; case '!': op.not++; break; } } if(op.plus!=0) n1++; if(op.minus!=0) n1++; if(op.modulo!=0) n1++; if(op.division!=0) n1++; if(op.multiply!=0) n1++; if(op.and!=0) n1++; if(op.or!=0) n1++; if(op.not!=0) n1++; N1=op.plus+op.minus+op.division+op.multiply+op.modulo+op.and+op.or+op.not; fclose(fs); } int cal(FILE *fs, int number,char *str, char ch,char *temp) { FILE *ft; int i,flag,length; ft=fs; temp[0]=ch; length=strlen(str); // printf("lenght = %d\n",length); for(i=1;i<=length;i++) temp[i]=fgetc(ft); //for comparing the strings storing in a temp string flag=0; flag=strcmp(temp,str); if(flag==1) { while(1) { ch=fgetc(ft); if(ch==';') { number++; break; } if(ch==',') number++; } fs=ft; } return number; } void distinct_operands(char *filename) { FILE *fs,*ft; char ch,*str_int="int ",*str_float="float ",*str_char="char ",temp[11],*str_file="FILE "; int i=0,flag; fs=fopen(filename,"r+"); if(fs==NULL) { printf("File Not Found"); exit(EXIT_FAILURE); } while(1) { ch=fgetc(fs); if(ch==EOF) break; if(str_int[0]==ch) opd.number_of_int = cal(fs,opd.number_of_int,str_int,ch,temp); else if(str_float[0]==ch) opd.number_of_float = cal(fs,opd.number_of_float,str_float,ch,temp); else if(str_char[0]==ch) opd.number_of_char = cal(fs,opd.number_of_char,str_char,ch,temp); else if(str_file[0]==ch) { opd.number_of_file = cal(fs,opd.number_of_file,str_file,ch,temp); } else if(ch=='\t') continue; else if(ch==' ') continue; else { while(1) { if(ch == '\n') break; else if(ch==EOF) goto L; ch = fgetc(fs); } } } L: n2 = opd.number_of_int + opd.number_of_char + opd.number_of_float+opd.number_of_file; fclose(fs); } void total_operands(char *filename) { FILE *fs,*ft,*fe; static count=0; char ch,ch1; fs = fopen(filename, "r+"); if(fs==NULL) { printf("FILE CANNOT BE OPENED"); exit(EXIT_FAILURE); } while(1) { ch=fgetc(fs); if(ch==EOF) break; if(ch=='=') { fe = fs; ch1 = fgetc(fe); if(ch1=='=') { count++; fs = fe; continue; } count++; // for the operand before the = sign while(1) { ch=fgetc(fs); switch(ch) { case ';': goto z; break; case '+': case '-': case '*': case '/': case '%': count++; } } z: count++; // as one operand count will be left so this for that one to add } } N2=count; fclose(fs); } int main() { char filename[20],ch; int N; double E,V,D,T; printf("\t\t\t**** HALSTEAD EQUATION ****"); Start: printf("\n\nEnter the file name\t"); gets(filename); find_operators(filename); distinct_operands(filename); total_operands(filename); C: printf("\nYou want to enter more file names(y/n)?\t"); scanf("%c",&ch); fflush(stdin); switch(ch) { case 'Y': case 'y': goto Start; break; case 'n': case 'N': break; default: printf("\n\n\t\tWrong Choice\n"); goto C; } printf("\nNumber of distinct operators n1= %d",n1); printf("\n\nTotal operators N1= %d",N1); printf("\n\nNumber of distinct operands n2= %d",n2); printf("\n\nTotal operands N2= %d",N2); printf("\n\nProgram vocabulary n= %d",n1+n2); N = N1 + N2 ; printf("\n\nProgram length n= %d",N); printf("\n\nCalculated program length = %0.5lf",n1*(log10((double)n1)/log10(2)) +n2*(log10((double)n1)/log10(2))); V = N * ( log10((double)(n1 + n2)) / log10(2) ); printf("\n\nVolume is V=%0.4lf",V); D = ( n1 * N2 ) / ( double )( 2 * n2 ) ; printf("\n\nDifficulty is D=%0.4lf",D); E=D*V; printf("\n\nEffort is E= %0.4lf",E); T = E / 18 ; printf("\n\nTime reqired T= %0.4lf sec",T); getch(); } Output: PROGRAM 2 Objective: Compute average number of live variables per statement in a program. Solution: #include<stdio.h> #include<stdlib.h> int total_number_of_lines; int live_var; void life_of_var(char *filename) { FILE *fs; char ch; fs = fopen (filename,"r+"); if(fs==NULL) { printf("\nFILE CANNOT BE OPENED "); exit(EXIT_FAILURE); } while(1) { ch=fgetc(fs); if(ch==EOF) break; else if(ch=='\n') total_number_of_lines++; else if(ch=='"') { ch=fgetc(fs); while(ch!='"') { if(ch=='%') live_var++; ch=fgetc(fs); } } else if(ch=='=') { live_var++; ch=fgetc(fs); while(ch!=';') { switch(ch) { case '+': case '-': case '*': case '%': case '/': live_var++; } ch=fgetc(fs); } live_var++; } } fclose(fs); } int main() { char filename[10],ch; printf("\t\t**** Average life of variables ****"); Start: printf("\n\nEnter the file name\t"); gets(filename); life_of_var(filename); C: printf("\nYou want to enter more file names(y/n)?\t"); scanf("%c",&ch); fflush(stdin); switch(ch) { case 'Y': case 'y': goto Start; break; case 'n': case 'N': break; default: printf("\n\n\t\tWrong Choice\n"); goto C; } printf("\nNumber of live variavbles %d",live_var); printf("\nNumber of lines %d",total_number_of_lines); printf("\nAverage number of live variable %f",(float)live_var/total_number_of_lines); getch(); } Output: PROGRAM 3 Objective: Compute average life of variables in a program. Solution: #include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct { char str[32]; }total_var; total_var tv[4000]; int j=0; int times=0; FILE* count_var(FILE *fs,int check) { char ch,*var; var = (char*)malloc(20* sizeof(char)); int i=0; while(1) { ch = fgetc(fs); if(ch == ';') { var[i] = '\0' ; strcpy(tv[j].str,var); i=0; j++; break; } else if(ch == ',') { var[i] = '\0' ; strcpy(tv[j].str,var); i=0; j++; } // else if(ch!=' ' && ch!='\\\t') else if((ch >='A'&& ch<='Z')|| ch>='a' && ch<='z' ) { if(i==0&&check==1) continue; else { var[i] = ch; i++; } } } free(var); return fs; } FILE* get_var_type(FILE *fs,char *str) { FILE *ft; ft=fs; char temp[8]; int check = 0; if(str[0]=='F') { check = 1; } temp[0] = str[0]; int p = strlen(str),i; for(i=1;i<p;i++) { temp[i] = fgetc(ft); } if(strcmp(temp,str)==0) { //puts(str); // puts(temp); fs = ft; fs = count_var(fs,check); } return fs; } void get_variables(char *filenam) { FILE *fs,*ft; char ch, *str_int = "int ",*str_float = "float ",*str_char = "char ",*str_file = "FILE "; fs = fopen(filenam,"r+"); if(fs == NULL) { printf("FILE CANNOT BE OPENED"); exit(1); } while(1) { ch = fgetc(fs); if(str_int[0]==ch) { fs = get_var_type(fs,str_int); } else if(str_float[0] == ch) { fs = get_var_type(fs,str_float); } else if(str_char[0] == ch) { fs = get_var_type(fs,str_char); } else if(str_file[0] == ch) { fs = get_var_type(fs,str_file); } else if(ch==EOF) break; else if(ch=='\t'|| ch==' ') continue; else { while(1) { if(ch == '\n') break; else if(ch==EOF) goto L; ch = fgetc(fs); } } } L: fclose(fs); } FILE* get_number_of_time(FILE *fs,char *str) { FILE *ft; ft=fs; char temp[32]; temp[0] = str[0]; int p = strlen(str),i; for(i=1;i<p;i++) { temp[i] = fgetc(ft); } temp[i] = '\0'; if(strcmp(temp,str)==0) { fs = ft; times++; } return fs; } void average_life(char *filenam) { int i=0,f=0; char ch; FILE *fs; A: fs = fopen(filenam,"r"); if(fs==NULL) { printf("File not found"); exit(1); } while(1) { ch = fgetc(fs); if(tv[i].str[0]==ch) { fs = get_number_of_time(fs,tv[i].str); if(f==0) { times--; f=1; } } else if(ch==EOF) { f=0; break; } } if(f==0 && i<j) { fclose(fs); i++; goto A; } // printf("times = %d",times); } int lines(char *filenam) { int i=0; char ch; FILE *fs; A: fs = fopen(filenam,"r"); if(fs==NULL) { printf("File not found"); exit(1); } while(1) { ch = fgetc(fs); if(ch=='\n') i++; if(ch==EOF) break; } fclose(fs); return i; } main() { char filenam[20],ch; Start: printf("\n\nEnter the file name\t"); gets(filenam); get_variables(filenam); average_life(filenam); int l = lines(filenam); C: printf("\nYou want to enter more file names(y/n)?\t"); scanf("%c",&ch); fflush(stdin); switch(ch) { case 'Y': case 'y': goto Start; break; case 'n': case 'N': break; default: printf("\n\n\t\tWrong Choice\n"); goto C; }printf("ans is %f",(float)times/l); getch(); } Output: PROGRAM 4 Objective: To perform boundary value analysis of a program. Solution: #include<iostream> #include<stdlib.h> using namespace std; int main() { int n,a[n],x,c,u[n],m[n],e[n][4]; cout<<"Enter the number of variables"; cin>>n; cout<<"Enter the Lower, and Upper Limits of the variables"; for(int y=1; y<n+1; y++) { cin>>m[y]; cin>>u[y]; } for(x=1; x<n+1; x++) { a[x] = (m[x] + u[x])/2; } c=(n*4)-4; for(int a1=1; a1<n+1; a1++) { e[a1][0] = m[a1]; e[a1][1] = m[a1]+1; e[a1][2] = u[a1]-1; e[a1][3] = u[a1]; } for(int i=1; i<n+1; i++) { for(int l=1; l<=i; l++) { if(l!=1) { cout<<a[l]<<"\t"; } } for(int j=0; j<4; j++) { cout<<e[i][j]; for(int k=0; k<n-(i+1); k++) { cout<<a[k]<<"\t"; } cout<<"\n"; } } system("PAUSE"); return 0; } OUTPUT: PROGRAM 5 Objective: Compute McCabe’s cyclomatic complexity of a program. Solution: #include<stdio.h> #include<conio.h> #include<stdlib.h> #define MAX 10 int main() { FILE *fp; int row,col,i,j,edges,nodes; char ch; int mat[MAX][MAX]; // clrscr(); fp=fopen("myfile.txt","r"); row=col=0; while(fscanf(fp,"%c",&ch)!=EOF) { if(ch==' ') col++; else if(ch=='\n') { row++; col=0; } else mat[row][col]=ch-48; } fclose(fp); printf("\nThe given adjacency matrix is : \n"); for(i=0;i<=row;i++) { for(j=0;j<=col;j++) printf("%d\t",mat[i][j]); printf("\n"); } nodes=row+1; printf("\nNumber of nodes = %d",nodes); edges=0; for(i=0;i<=row;i++) { for(j=0;j<=col;j++) { if(mat[i][j]==1) edges++; } } printf("\nNumber of edges = %d",edges); printf("\n\nCyclometic Complexity of graph = edges-nodes+2p\n"); printf("\t\t\t\t= %d - %d + 2",edges,nodes); printf("\n\t\t\t\t= %d",edges-nodes+2); getch(); } OUTPUT: