Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include <iostream> 00003 #include "conio.h" 00004 #include "Serial.h" 00005 Serial uart1(USBTX,USBRX); 00006 00007 int main() 00008 { 00009 uart1.baud(9600); 00010 wait(0.1); 00011 iint i,j,l; 00012 int tsc=12; 00013 char gen[12]={'F','M','F','F','F','M','F','M','M','F','M','F'}; 00014 float h[12]={1.6f,2.0f,1.9f,1.88f,1.7f,1.85f,1.6f,1.7f,2.2f,1.8f,1.95f,1.9f}; 00015 char op[12][10]={"short","tall","medium","medium","short","medium","short","short","tall","medium","medium","medium"}; 00016 00017 uart1.printf("\n Initial Set:"); 00018 uart1.printf("\nGender\tHeight\tOutput"); 00019 for(i=0;i<12;i++) 00020 { 00021 uart1.printf("%d, %d, %d \n",gen[i], h[i], op[i]); 00022 } 00023 00024 float nh; 00025 char ng; 00026 uart1.printf("\n Enter tuple to be processed (Height,Gender) :"); 00027 cin>>nh>>ng; 00028 00029 int t; 00030 uart1.printf("\n Enter threshold:"); 00031 cin>>t; 00032 00033 float d[12][2],k; 00034 00035 //calculating distance to each value in training set 00036 for(i=0;i<12;i++) 00037 { 00038 d[i][0]=i; 00039 k=h[i]-nh; 00040 if(k<0) 00041 { 00042 d[i][1]=-k; 00043 } 00044 else 00045 { 00046 d[i][1]=k; 00047 } 00048 } 00049 00050 //Sorting 00051 for(i=0;i<11;i++) 00052 { 00053 for(j=0;j<11;j++) 00054 { 00055 if(d[j][1]>d[j+1][1]) 00056 { 00057 k=d[j][1]; 00058 d[j][1]=d[j+1][1]; 00059 d[j+1][1]=k; 00060 00061 l=d[j][0]; 00062 d[j][0]=d[j+1][0]; 00063 d[j+1][0]=l; 00064 } 00065 } 00066 } 00067 00068 int nos=0; //no of shorts 00069 int nom=0; //no of mediums 00070 int not=0; //no of talls 00071 00072 uart1.printf("\nGender\tHeight\tOutput\n"); 00073 for(i=0;i<t;i++) 00074 { 00075 l=d[i][0]; 00076 uart1.printf("%d, %d, %d\n",gen[l],h[l],op[l]); 00077 if(strcmp(op[l],"short")==0) 00078 { 00079 nos++; 00080 } 00081 if(strcmp(op[l],"medium")==0) 00082 { 00083 nom++; 00084 } 00085 if(strcmp(op[l],"tall")==0) 00086 { 00087 not++; 00088 } 00089 } 00090 00091 uart1.printf("\n No of shorts:")<<nos; 00092 uart1.printf("\n No of medium:")<<nom; 00093 uart1.printf("\n No of tall:")<<not; 00094 00095 if(nos>nom&&nos>not) 00096 { 00097 uart1.printf("\n New Tuple is classified as Short"); 00098 } 00099 00100 if(nom>nos&&nom>not) 00101 { 00102 uart1.printf("\n New Tuple is classified as Medium"); 00103 } 00104 00105 if(not>nom&¬>nos) 00106 { 00107 uart1.printf("\n New Tuple is classified as Tall"); 00108 } 00109 00110 getch(); 00111 } 00112 00113
Generated on Thu Jul 28 2022 01:19:16 by
1.7.2