0% found this document useful (0 votes)
83 views6 pages

Lab1: Test Driven Development (C++) Name: Ayesha Irfan (32969) Class: B-EE-6-C

The document describes a student's work on a lab assignment involving test driven development in C++. It includes 3 tasks - the first involves writing a simple program to demonstrate pointers, the second defines a function to find the minimum number in an array and tests it with sample cases, and the third sorts an integer array using bubble sort and tests it on sample cases. The student provides the code for each task and test cases with expected and actual outputs to validate that the programs are working as intended.

Uploaded by

Ayesha Irfan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views6 pages

Lab1: Test Driven Development (C++) Name: Ayesha Irfan (32969) Class: B-EE-6-C

The document describes a student's work on a lab assignment involving test driven development in C++. It includes 3 tasks - the first involves writing a simple program to demonstrate pointers, the second defines a function to find the minimum number in an array and tests it with sample cases, and the third sorts an integer array using bubble sort and tests it on sample cases. The student provides the code for each task and test cases with expected and actual outputs to validate that the programs are working as intended.

Uploaded by

Ayesha Irfan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab1: Test Driven Development (C++)

Name: Ayesha Irfan (32969)


Class: B-EE-6-C

Lab Task 0:
Program:
#include <stdio.h>
#include <conio.h>
using namespace std;
int main(){
int number;
int *ptr;
cout<<"Enter number: "<<endl;
cin>>number;
ptr=&number;
cout<<"Number is "<<endl;
cout<<number<<endl;
cout<<"Memory address is: "<<endl;
cout<<ptr<<endl;
_getch();
return 0;

Lab Task 1:
Program:
#include <iostream>
#include <stdio.h>
#include <conio.h>
using namespace std;
int minimum(int minval,int array1[]);
int minimum(int minval,int array1[])
{
int choice;
cout<<"For TEST CASE 1-FOR
cout<<"For TEST CASE 2-FOR
cout<<"For TEST CASE 3-FOR
cout<<"For TEST CASE 4-FOR
cin>>choice;
switch(choice){
case 1:{
int min=array1[0];

TWO NATURAL NOS -Press 1\n";


THREE NATURAL NOS-Press 2\n";
FOUR NATURAL NOS numbers-Press 3\n";
FIVE NATURAL NOS numbers-Press 4\n";

for(int i=0;i<2;i++){
if (array1[i]<minval){
minval=array1[i];
}
}

cout<<"Minimum is " <<minval<<endl;


return minval;
}
case 2:{
int min=array1[0];
for(int i=0;i<3;i++){
if (array1[i]<minval){
minval=array1[i];
}
}
cout<<"Minimum is " <<minval<<endl;
return minval;
}
case 3:{
int min=array1[0];
for(int i=0;i<4;i++){
if (array1[i]<minval){
minval=array1[i];
}
}
cout<<"Minimum is " <<minval<<endl;
return minval;
}
case 4:{
int min=array1[0];
for(int i=0;i<5;i++){
if (array1[i]<minval){
minval=array1[i];
}
}
cout<<"Minimum is " <<minval<<endl;
return minval;
}
}
}
int main(){
int array[2]={0,3};
int min=array[0];
//Test case 1 for 2 NATURAL NOS
//Input {0,3}
//Expected Output = 0
//Execution
if (minimum(min,array)==0){
cout << "Test case 1 : PASS" << endl;
}else{
cout << "Test case 1 : FAIL" << endl;
}
int array1[3]={67,45,23};
int mini=array1[0];
//Test case 2 FOR 3 NATURAL NOS

//Input {67,45,23}
//Expected Output = 23
//Execution
if (minimum(mini,array1)==23){
cout << "Test case 2 : PASS" << endl;
}else{
cout << "Test case 2 : FAIL" << endl;
}
int array2[4]={12,97,8,11};
int minim=array2[0];
//Test case 3 FOR 4 NATURAL NOS
//Input {12,97,8,11}
//Expected Output = 8
//Execution
if (minimum(minim,array2)==8){
cout << "Test case 3: PASS" << endl;
}else{
cout << "Test case 3 : FAIL" << endl;
}
int array3[5]={12,97,8,125,7};
int minime=array3[0];
//Test case 3 FOR 5 NATURAL NOS
//Input {12,97,8,125,7}
//Expected Output = 8
//Execution
if (minimum(minime,array3)==7){
cout << "Test case 3: PASS" << endl;
}else{
cout << "Test case 3 : FAIL" << endl;
}

_getch();
return 0;

Lab Task 2:
Program:
#include <iostream>
#include <stdio.h>
#include <conio.h>
using namespace std;
void sort(int arr[] , int len);
int main(){
int array[5];
int length=5;
for(int x=0;x<5;x++){
cout<<"Enter number: "<<endl;

cin>>array[x];
}
sort(array, length);
_getch();
return 0;

}
void sort(int arr[], int len){

for(int i=0;i<len;i++){
for(int j=0;j<len-1;j++){

}
}

if(arr[j+1]<arr[j]){
int temp = arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}

cout<<"The ascending order is: "<<endl;


for(int i=0;i<len;i++){
cout<<arr[i]<<endl;
}

Function:
void sort(int arr[], int len){
for(int i=0;i<len;i++){
for(int j=0;j<len-1;j++){

}
}

if(arr[j+1]<arr[j]){
int temp = arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}

cout<<"The ascending order is: "<<endl;


for(int i=0;i<len;i++){
cout<<arr[i]<<endl;
}

CASE 1:
Inputs: 34, 28,78,16,13
MY Outputs: 13,16,28,34,78
Program Output:

Hence Case 1: Passed

CASE 2:
Inputs: 5,11,3,7,2
MYoutput:2,3,5,7,11
Program Output:

Hence Case 2:Passed

CASE 3:
Inputs: 105,45,120,150,89
Outputs:45,89,105,120,150
Program Output:

Hence Case 3:Passed

You might also like