/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /* * File: main.cpp * Author: dell * * Created on 14 Δεκεμβρίου 2018, 2:37 μμ */ #include using namespace std; void printC(char *t, int size) { for (int i=0; i> t[i]; } return t; } double * multiply2Arrays(double *t1, double *t2, int size) { double *multiTable= new double[size]; for (int i=0; i= downLimit) && (t[i] <= upLimit) ) { result=result * t[i]; // result *= t[i] inRangeCounter++; } } if (inRangeCounter == 0) result= -1; return result; } bool positiveNegativeCount(double *d, int size, int & posCount, int & negCount) { posCount=0; negCount=0; for (int i=0; i 0.0 ) posCount++; if (d[i] < 0.0 ) negCount++; } if (posCount==0 && negCount==0) return false; else return true; } bool expandTrue( bool *& t, int oldSize, int times, int & newSize) { if (findTrueCount(t, oldSize) != oldSize) return false; delete [] t; newSize= times* oldSize; bool *expandedArray= new bool[newSize]; for (int i=0; i< newSize; i++) expandedArray[i] = true; t=expandedArray; return true; } /* * */ int main(int argc, char** argv) { halfAlphabet(false); char *half= halfAlphabet2(true); printC(half,13); delete[] half; f30(1); int *myTbl= f30b(1); printI(myTbl,30); delete[] myTbl; int size=5; /*double *myTbl2= fillArray(size); printD(myTbl2, size); delete []myTbl2; */ double *tbl1= new double[size]; tbl1[0]=1.1; tbl1[1]=2.0; tbl1[2]=3.0; tbl1[3]=4.0; tbl1[4]=5.0; double *tbl2= new double[size]; tbl2[0]=1.1; tbl2[1]=2.0; tbl2[2]=3.0; tbl2[3]=4.0; tbl2[4]=5.0; double *mArray= multiply2Arrays(tbl1,tbl2,size); printD(mArray,size); delete []tbl1; delete []tbl2; delete []mArray; bool *tbl3= new bool[size]; tbl3[0]= false; tbl3[1]=true; tbl3[2]=true; tbl3[3]=true; tbl3[4]=true; printB(tbl3,size); tbl3=shiftArrayOne(tbl3,size); printB(tbl3,size); tbl3=shiftArrayOne(tbl3,size); printB(tbl3,size); tbl3=shiftArrayMany(tbl3,size,3); printB(tbl3,size); delete []tbl3; cout << endl; bool squareTbl[5][5] = { {1,1,1,1,1}, {1,1,0,0,1}, {1,0,1,0,1}, {1,0,0,1,1}, {1,1,1,1,1} }; showSquareArray(squareTbl); cout << endl; reverseDiagonal(squareTbl); showSquareArray(squareTbl); int *tbl4= new int[5]; tbl4[0]=1; tbl4[1]=2; tbl4[2]=3; tbl4[3]=4; tbl4[4]=5; if (nonZero(tbl4, 5)) cout << "None is zero " << endl; else cout << "One or more are zero " << endl; tbl4[1]= 0; if (nonZero(tbl4, 5)) cout << "None is zero " << endl; else cout << "One or more are zero " << endl; delete [] tbl4; bool *tbl5= new bool[4]; tbl5[0]= false; tbl5[1]=true; tbl5[2]=true; tbl5[3]=true; int c=findTrueCount(tbl5,4); cout << "Count of true: " << c << endl; delete []tbl5; tbl4= new int[5]; tbl4[0]=10; tbl4[1]=20; tbl4[2]=30; tbl4[3]=40; tbl4[4]=50; cout << multiplyInRange(tbl4, 5, 20, 40) << " " << multiplyInRange(tbl4, 5, 120, 140) << endl; delete [] tbl4; tbl2= new double[5]; tbl2[0]= -1.1; tbl2[1]= -2.0; tbl2[2]=0.0; tbl2[3]=4.0; tbl2[4]=5.0; int positiveCount, negativeCount; if ( positiveNegativeCount(tbl2,5, positiveCount, negativeCount) ) cout << "Positive numbers: " << positiveCount << "\t\t Negative numbers: " << negativeCount << "\n"; else cout << "All numbers are zero " << endl; tbl2[0]= 0; tbl2[1]= 0; tbl2[2]=0.0; tbl2[3]=0.0; tbl2[4]=0.0; if ( positiveNegativeCount(tbl2,5, positiveCount, negativeCount) == true) cout << "Positive numbers: " << positiveCount << "\t\t Negative numbers: " << negativeCount << "\n"; else cout << "All numbers are zero " << endl; delete []tbl2; size=4; tbl5= new bool[size]; tbl5[0]= false; tbl5[1]=true; tbl5[2]=true; tbl5[3]=true; int expandedSize=0; bool tableExpanded= expandTrue(tbl5,size, 4, expandedSize); if (tableExpanded) { cout << "Show expanded array...\n"; printB(tbl5,expandedSize); } else { cout << "Show not expanded array...\n"; printB(tbl5,size); } tbl5[0]= true; tableExpanded= expandTrue(tbl5,size, 4, expandedSize); if (tableExpanded) { cout << "Show expanded array...\n"; printB(tbl5,expandedSize); } else { cout << "Show not expanded array...\n"; printB(tbl5,size); } delete []tbl5; return 0; }