diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..ae55d15 Binary files /dev/null and b/.DS_Store differ diff --git a/Suriya/.DS_Store b/Suriya/.DS_Store new file mode 100644 index 0000000..41019dd Binary files /dev/null and b/Suriya/.DS_Store differ diff --git a/Suriya/Assignment1/.DS_Store b/Suriya/Assignment1/.DS_Store new file mode 100644 index 0000000..2b93ed7 Binary files /dev/null and b/Suriya/Assignment1/.DS_Store differ diff --git a/Suriya/Assignment1/Account.cpp b/Suriya/Assignment1/Account.cpp new file mode 100644 index 0000000..43e056b --- /dev/null +++ b/Suriya/Assignment1/Account.cpp @@ -0,0 +1,34 @@ +//Exercise 3.12 - Class Source File +//ex3_12-Account.cpp + +#include +#include "Account.h" +using namespace std; + +Account::Account(int number) { + setBalance(number); +} + +void Account::setBalance(int number) { + if (number>=0) + balance = number; + if (number<0) { + balance = 0; + cout << "Error: Invalid value. Balance set to 0." << endl; + } +} + +int Account::getBalance() { + return balance; +} + +void Account::credit(int cred) { + setBalance(getBalance()+cred); +} + +void Account::debit(int deb) { + if (deb<=getBalance()) + setBalance(getBalance()-deb); + if (deb>getBalance()) + cout<<"Debit amount exceeded account balance."< +#include "Date.h" +using namespace std; + +Date::Date(int month1, int day1, int year1) { + setDay(day1); + setMonth(month1); + setYear(year1); +} + +void Date::setDay(int day1) { + day = day1; +} + +void Date::setMonth(int month1) { + if (month1<1 || month1>12){ + month = 1; + cout<<"Invalid month input. Month set to January"<=1 && month1<=12) + month = month1; +} + +void Date::setYear(int year1) { + year = year1; +} + +void Date::displayDate() { + cout<<"Recorded date is: "< +using namespace std; + +class Date{ + public: + Date(int, int, int); + void setDay(int); + void setMonth(int); + void setYear(int); + void displayDate(); + + private: + int day,month,year; +}; \ No newline at end of file diff --git a/Suriya/Assignment1/Employee.cpp b/Suriya/Assignment1/Employee.cpp new file mode 100644 index 0000000..3ec78fb --- /dev/null +++ b/Suriya/Assignment1/Employee.cpp @@ -0,0 +1,43 @@ +//Exercise 3.14 - Class Source File +//ex3_14-Employee.cpp + +#include +#include +#include "Employee.h" +using namespace std; + +Employee::Employee(string f_name, string l_name, int pay){ + setFirstName(f_name); + setLastName(l_name); + setSalary(pay); +} + +void Employee::setFirstName(string f_name) { + fname = f_name; +} + +void Employee::setLastName(string l_name) { + lname = l_name; +} + +void Employee::setSalary(int pay) { + if (pay>=0) + salary = pay; + if (pay<0){ + cout<<"Invalid value. Salary set to 0."< +using namespace std; + +class Employee{ + public: + Employee(string, string, int); + void setFirstName(string); + void setLastName(string); + void setSalary(int); + string getEmployeeName(); + int getEmployeeSalary(); + void displayAnnualSalary(); + + private: + string fname, lname; + int salary; +}; \ No newline at end of file diff --git a/Suriya/Assignment1/GradeBook.cpp b/Suriya/Assignment1/GradeBook.cpp new file mode 100644 index 0000000..e5d4133 --- /dev/null +++ b/Suriya/Assignment1/GradeBook.cpp @@ -0,0 +1,34 @@ +//Exercise 3.11 - Class Source File +//ex3_11-GradeBook.cpp + +#include +#include +#include "GradeBook.h" + +using namespace std; + +GradeBook::GradeBook( string name, string instr ) { + setCourseName( name ); + setCourseInstr( instr ); +} + +void GradeBook::setCourseName( string name ) { + courseName = name; +} + +void GradeBook::setCourseInstr( string instr) { + courseInstr = instr; +} + +string GradeBook::getCourseName() { + return courseName; +} + +string GradeBook::getCourseInstr() { + return courseInstr; +} + +void GradeBook::displayMessage() { + cout << "Welcome to the grade book for\n" << getCourseName() << "!\n" + << "This course is presented by: " << getCourseInstr() << ".\n" < +using namespace std; + +class GradeBook +{ + public: + GradeBook( string, string ); + void setCourseName( string ); + void setCourseInstr( string ); + string getCourseName(); + string getCourseInstr(); + void displayMessage(); + + private: + string courseName,courseInstr; +}; diff --git a/Suriya/Assignment1/Invoice.cpp b/Suriya/Assignment1/Invoice.cpp new file mode 100644 index 0000000..3e7e4d0 --- /dev/null +++ b/Suriya/Assignment1/Invoice.cpp @@ -0,0 +1,60 @@ +//Exercise 3.13 - Class Source File +//ex3_13-Invoice.cpp + +#include +#include +#include "Invoice.h" +using namespace std; + +Invoice::Invoice(string partnumb, string partdescript, int quan, int price1){ + setPartNumber(partnumb); + setPartDescript(partdescript); + setQuant(quan); + setPrice(price1); +} + +void Invoice::setPartNumber(string partnumb){ + partNumber = partnumb; +} + +void Invoice::setPartDescript(string partdescript){ + partDescript = partdescript; +} + +void Invoice::setQuant(int quan){ + if (quan>=0) + quant = quan; + if (quan<0){ + cout<<"Invalid input value. Quantity set to 0."<=0) + price = price1; + if (price1<0){ + cout<<"Invalid input value. Price set to 0."< +using namespace std; + +class Invoice{ + public: + Invoice(string,string,int,int); + void setPartNumber(string); + void setPartDescript(string); + void setQuant(int); + void setPrice(int); + string getPartNumber(); + string getPartDescript(); + int getQuant(); + int getPrice(); + int getInvoiceAmount(); + + private: + string partNumber, partDescript; + int quant, price; + +}; \ No newline at end of file diff --git a/Suriya/Assignment1/ex2_19_main.cpp b/Suriya/Assignment1/ex2_19_main.cpp new file mode 100644 index 0000000..907d19e --- /dev/null +++ b/Suriya/Assignment1/ex2_19_main.cpp @@ -0,0 +1,41 @@ +//Exercise 2.19 +//ex2_19-main.cpp + +#include + +using namespace std; + +int main() { + int a,b,c; + cout << "Input three different integers: "; + cin >> a >> b >> c; + cout << "Sum is "<< a+b+c <c) + cout<<"Smallest is "<b){ + if (b<=c) + cout<<"Smallest is "<c) + cout<<"Smallest is "<=b){ + if (a>=c) + cout<<"Largest is "<=c) + cout<<"Largest is "< + +using namespace std; + +int main() { + int a; + cout << "Enter an integer: "; + cin >> a; + if (a%2 == 0) + cout << a <<" is even"< + +using namespace std; + +int main() { + int a, b; + cout << "Enter two integers: "; + cin >> a >> b; + if (a%b == 0) + cout << a <<" is a multiple of "<< b < + +using namespace std; + +int main() { + int a; + cout << "Enter a five-digit integer: "; + cin >> a; + if (a/10000 > 0) + cout< +#include "GradeBook.h" + +using namespace std; + +int main() +{ + GradeBook gradeBook1( "M E 666 Finite Element Methods", "James Rossmanith" ); + GradeBook gradeBook2( "M E 546 Computational Fluid Dynamics I", "Paul Durbin" ); + cout << "gradeBook1 created for course: " << gradeBook1.getCourseName() + <<"\ngradeBook2 created for course: " << gradeBook2.getCourseName()<< "\n"< +#include "Account.h" + +using namespace std; + +int main() { + Account account1(1750), account2(-20); + cout << "Account1 created with balance:" << account1.getBalance() + <<"\nAccount2 created with balance: " << account2.getBalance()<< "\n"< +#include "Invoice.h" + +using namespace std; + +int main() { + Invoice invoice1("17m150","Flash Drive",3,40), invoice2("17m151","Thermometer",-6,15); + cout << "Invoice created for product id: " << invoice1.getPartNumber() + <<"\nInvoice created for product id: " << invoice2.getPartNumber()<< "\n"< +#include "Employee.h" +using namespace std; + +int main() { + Employee employee1("Sheldon","Cooper",72000), employee2("Leonard","Hofstader",-70000); + cout << "Employee record created for: " << employee1.getEmployeeName() + <<"\nEmployee record created for: " << employee2.getEmployeeName()<< "\n"< +#include "Date.h" +using namespace std; + +int main(){ + Date date1(13,14,2020), date2(10,21,1999); + cout<<"Date record created for date1\n" + <<"Date record created for date2"< + +using namespace std; + +int main() { + int miles=0, gallons=1; + int totmiles=0, totgallons=0; + cout<<"Enter miles driven (-1 to quit): "; + cin>>miles; + while (miles!=-1){ + cout<<"Enter gallons used: "; + cin>>gallons; + if (gallons>0){ + totmiles+=miles; + totgallons+=gallons; + cout<<"MPG this trip: "<(miles)/gallons; + cout<<"\nTotal MPG: "<(totmiles)/totgallons<>miles; + } + cout<<"\nEnd of program"< + +using namespace std; + +int main() { + int a; + cout<<"Enter a five digit number: "; + cin>>a; + if (a/10000>0) { + if ((a / 10000) == (a % 10)) { + if (((a / 1000) % 10) == ((a % 100) / 10)) + cout << "It's a Palindrome!" << endl; + else + cout << "It's not a Palindrome!" << endl; + } + else + cout << "It's not a Palindrome!" << endl; + } + else + cout<<"Invalid input"< + +using namespace std; + +int main() { + int binary, powertwo=1; + int a, decimal = 0, breaker=1; + cout<<"Enter a binary number: "; + cin>>binary; + while (binary!=0 && breaker!=0){ + a = binary%10; + if (a==0 || a==1){ + decimal = decimal + (a*powertwo); + powertwo = 2 * powertwo; + binary = binary/10; + } + else { + breaker = 0; + } + } + if (breaker==1) + cout<<"Decimal equivalent: "< +using namespace std; + +int main(){ + + //part(a) + int number,i=1, product=1; + cout<<"Part (a): Enter an integer calculating its factorial: "; + cin>>number; + if (number==0) + cout<<"Factorial of "<>number; + if (number<=0) + cout<<"Invalid input."<>x; + cout<<"Enter the number of terms (in the summation) for the estimation of its exponential: "; + cin>>number; + if (number<=0) + cout<<"Invalid input."< +using namespace std; + +int main(){ + int number; + int a, b, c, d, temp; + cout<<"Enter the integer to decrypt: "; + cin>>number; + a = ((number/1000) + 3) - (((number/1000) + 3)/10)*10; + b = ((number%1000)/100 + 3) - (((number%1000)/100 + 3)/10)*10; + c = ((number%100)/10 + 3) - (((number%100)/10 + 3)/10)*10; + d = ((number%10) + 3) - (((number%10) + 3)/10)*10; + temp = a; + a = c; + c = temp; + temp = b; + b = d; + d = temp; + cout<<"decrypted data: "< +using namespace std; + +int main() { + int number; + int a, b, c, d, temp; + cout<<"Enter a four digit integer to encrypt: "; + cin>>number; + a = ((number/1000) + 7) - (((number/1000) + 7)/10)*10; + b = ((number%1000)/100 + 7) - (((number%1000)/100 + 7)/10)*10; + c = ((number%100)/10 + 7) - (((number%100)/10 + 7)/10)*10; + d = ((number%10) + 7) - (((number%10) + 7)/10)*10; + temp = a; + a = c; + c = temp; + temp = b; + b = d; + d = temp; + cout<<"Encrypted data: "<< a*1000+b*100+c*10+d< +#include +#include + +using namespace std; + +int main() { + double pi = 4; + cout<=1000){ + cout< +#include + +using namespace std; + +int main(){ + cout<<" Pythagorean Triplets "< +#include + +using namespace std; + +int main(){ + //part(a) + cout<=5)" + <=5)"<=5))"<(x<5)< + (y>=5)<(!(x<5)&&!(y>=5))<(!((x<5)||(y>=5))) + <(x<5)< + (y>=5)<(!(x<5)&&!(y>=5))<(!((x<5)||(y>=5))) + <(x<5)< + (y>=5)<(!(x<5)&&!(y>=5))<(!((x<5)||(y>=5))) + <(x<5)< + (y>=5)<(!(x<5)&&!(y>=5))<(!((x<5)||(y>=5))) + <(a==b)<(g!=5)<(!(a==b)||!(g!=5))< + (!((a==b)&&(g!=5)))<(a==b)<(g!=5)<(!(a==b)||!(g!=5))< + (!((a==b)&&(g!=5)))<(a==b)<(g!=5)<(!(a==b)||!(g!=5))< + (!((a==b)&&(g!=5)))<(a==b)<(g!=5)<(!(a==b)||!(g!=5))< + (!((a==b)&&(g!=5)))<4)" + <4))"<4))"<(x<=8)< + (y>4)<(!((x<=8)&&(y>4)))<(!(x<=8)||!(y>4)) + <(x<=8)< + (y>4)<(!((x<=8)&&(y>4)))<(!(x<=8)||!(y>4)) + <(x<=8)< + (y>4)<(!((x<=8)&&(y>4)))<(!(x<=8)||!(y>4)) + <(x<=8)< + (y>4)<(!((x<=8)&&(y>4)))<(!(x<=8)||!(y>4)) + <4)"<4)||(j<=6))"<4)&&!(j<=6)"<(i>4)< + (j<=6)<(!((i>4)||(j<=6)))<(!(i>4)&&!(j<=6)) + <(i>4)<(j<=6)<(!((i>4)||(j<=6)))< + (!(i>4)&&!(j<=6))<(i>4)<(j<=6)<(!((i>4)||(j<=6)))< + (!(i>4)&&!(j<=6))<(i>4)<(j<=6)<(!((i>4)||(j<=6)))< + (!(i>4)&&!(j<=6))< +using namespace std; + +int main(){ + int count; + int i=1; + for ( count = 1; count <= 10 && i!=0; ++count ) { + cout << count << " "; + if ( count+1 == 5 ) //calculates for the succeeding group + i=0; + } + cout << "\nBroke out of loop at count = " << count << endl; +} \ No newline at end of file diff --git a/Suriya/Assignment3/CMakeLists.txt b/Suriya/Assignment3/CMakeLists.txt new file mode 100644 index 0000000..87ebcbe --- /dev/null +++ b/Suriya/Assignment3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.23) +project(Assignment3) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(ex6_16 ex6_16.cpp) +add_executable(ex6_17 ex6_17.cpp) +add_executable(ex6_18 ex6_18.cpp) +add_executable(ex6_26 ex6_26.cpp) +add_executable(ex6_28 ex6_28.cpp) +add_executable(ex6_29 ex6_29.cpp) +add_executable(ex6_31 ex6_31.cpp) +add_executable(ex6_36 ex6_36.cpp) +add_executable(ex6_37 ex6_37.cpp) +add_executable(ex6_38 ex6_38.cpp) +add_executable(ex6_39 ex6_39.cpp) +add_executable(ex6_41 ex6_41.cpp) +add_executable(ex6_42 ex6_42.cpp) +add_executable(ex6_50 ex6_50.cpp) \ No newline at end of file diff --git a/Suriya/Assignment3/ex6_16.cpp b/Suriya/Assignment3/ex6_16.cpp new file mode 100644 index 0000000..08df9b6 --- /dev/null +++ b/Suriya/Assignment3/ex6_16.cpp @@ -0,0 +1,23 @@ +//Exercise 6.16 + +#include +#include + +using namespace std; + +int main() { + int n; + srand(time(0)); + n = 1 + rand()%2; + cout<<"Random generation of either 1 or 2: "<< n << endl; + n = 1 + rand()%100; + cout<<"Random integer generated from 1 to 100: "<< n < +#include + +using namespace std; + +int main(){ + srand(time(0)); + cout<<"Random number generated from {2, 4, 6, 8, 10} = "<< 2 * (1 + rand()%5) << endl; + cout<<"Random number generated from {3, 5, 7, 9, 11} = "<< 2 * (1 + rand()%5) + 1 << endl; + cout<<"Random number generated from {6, 10, 14, 18, 22} = "<< 4 * (1 + rand()%5) + 2 << endl; +} \ No newline at end of file diff --git a/Suriya/Assignment3/ex6_18.cpp b/Suriya/Assignment3/ex6_18.cpp new file mode 100644 index 0000000..dbe7ae9 --- /dev/null +++ b/Suriya/Assignment3/ex6_18.cpp @@ -0,0 +1,18 @@ +//Exercise 6.18 +#include +using namespace std; + +int integerPower(int, unsigned int); + +int main(){ + cout<<"The base 3 raised to the power 10 is "< +#include + +using namespace std; + +double celsius (int); +double fahrenheit (int); + +int main() { + double cel, fah; + cout << left << setw(10) << "CELCIUS" << setw(18) << "FAHRENHEIT" << "|| " + << setw(12) << "FAHRENHEIT" << setw(12) << "CELCIUS"<<"| " + << setw(12) << "FAHRENHEIT" << setw(10) << "CELCIUS"< +using namespace std; + +bool isPerfect(int); + +int main(){ + int sum; + for(int j=1; j<=1000; j++){ + if (isPerfect(j)){ + sum = 0; + cout<<"Number: "< +#include +#include + +using namespace std; + +bool isPrime(int); + +int main(){ + int rowCounter=0; + for(int number=1; number<=10000; number++){ + if(isPrime(number)){ + cout< +using namespace std; + +int gcd(int, int); + +int main(){ + cout<<"GCD of 11571 and 1767 is : "< +using namespace std; + +double power(int, int); + +int main(){ + cout<<"The base 30 raised to power 3 is "< +using namespace std; + +int fibonacci(int); +double fibonacci(double); + +int main(){ + int larIntFib, counter; + double larDoubFib, counter2; + + for(int i=1; fibonacci(i+1)>fibonacci(i) ; i++){ + larIntFib = fibonacci(i); + counter=i; + } + cout<<"The largest int number in the Fibonacci series is the "<fibonacci(j); j++){ + larDoubFib = fibonacci(j); + counter2=j; + } + cout<<"The largest double number in the Fibonacci series is the "< +using namespace std; + +void towerOfHanoi(int, int, int, int); + +int main(){ + towerOfHanoi(4,1,3,2); +} + +void towerOfHanoi(int noOfDisks, int initialPeg, int targetPeg, int tempPeg){ + if (noOfDisks==1) + cout<<"Move disk from peg "<< initialPeg <<" to "<< targetPeg << endl; + if (noOfDisks>1){ + towerOfHanoi(noOfDisks-1,initialPeg,tempPeg,targetPeg); + cout<<"Move disk from peg "<< initialPeg <<" to "<< targetPeg << endl; + towerOfHanoi(noOfDisks-1,tempPeg,targetPeg,initialPeg); + } +} \ No newline at end of file diff --git a/Suriya/Assignment3/ex6_39.cpp b/Suriya/Assignment3/ex6_39.cpp new file mode 100644 index 0000000..1fa12ab --- /dev/null +++ b/Suriya/Assignment3/ex6_39.cpp @@ -0,0 +1,34 @@ +//Exercise 6.39 + +#include + +using namespace std; + +void towerOfHanoi(int, int, int, int); + +int main(){ + towerOfHanoi(4,1,3,2); +} + +void towerOfHanoi(int noOfDisks, int initialPeg, int targetPeg, int tempPeg){ + int noOfMoves=0; + for (int i=1; i<=noOfDisks; i++){ + noOfMoves = 2 * noOfMoves + 1; + } + + if(noOfDisks%2==0){ + int interChanger; + interChanger=targetPeg; + targetPeg=tempPeg; + tempPeg=interChanger; + } + + for (int j=1; j<=noOfMoves; j++){ + if(j%3==1) + cout<<"Move disk from peg "< +using namespace std; + +int gcd(int, int); + +int main(){ + cout<<"The gcd of 11571 and 1767 is "<x){ + temp = x; + x = y; + y = temp; + } + if (y==0) + return x; + else + return gcd(y,x%y); +} \ No newline at end of file diff --git a/Suriya/Assignment3/ex6_42.cpp b/Suriya/Assignment3/ex6_42.cpp new file mode 100644 index 0000000..18c64b5 --- /dev/null +++ b/Suriya/Assignment3/ex6_42.cpp @@ -0,0 +1,15 @@ +//Exercise 6.42 + +#include +using namespace std; + +int main(){ + static int i=1; + i++; + if (i<=100) { + cout << i << endl; + main(); + } + //comment: the static variable 'i' is only initialised once. everytime the function main() is called, the 'i' holds + //its value from the previous iteration. +} \ No newline at end of file diff --git a/Suriya/Assignment3/ex6_50.cpp b/Suriya/Assignment3/ex6_50.cpp new file mode 100644 index 0000000..aef29ae --- /dev/null +++ b/Suriya/Assignment3/ex6_50.cpp @@ -0,0 +1,16 @@ +//Exercise 6.50 + +#include +#include +using namespace std; + +inline double circleArea(double radius){ + return 3.14*radius*radius; +} + +int main(){ + double rad; + cout<<"Enter radius: "; + cin>>rad; + cout<<"Area of the circle: "< +using namespace std; + +int main() { + const int arraySize = 10; + int temp = 0, noOfSwaps=1; + int c[arraySize] = {5, 6,3, 4,3,7,8,1,7,8}; + + cout<<"Array before bubble sorting algorithm: "< c[j+1]){ + temp = c[j]; + c[j] = c[j+1]; + c[j+1] = temp; + noOfSwaps++; + } + } + } + + cout<<"Array after bubble sorting algorithm: "< +using namespace std; + +int main() { + const int arraySize = 10; + int temp = 0, noOfSwaps = 1; + int c[arraySize] = {5, 6, 3, 4, 3, 7, 8, 1, 7, 8}; + + cout << "Array before bubble sorting algorithm: " << endl; + for (int i = 0; i < arraySize; i++) { + cout << c[i] << " "; + if (i == (arraySize - 1)) + cout << endl; + } + + for (int k=0; k<(arraySize-1) && noOfSwaps!=0; k++){ + noOfSwaps = 0; + for (int j=0; j<(arraySize-1-k); j++){ + if (c[j] > c[j+1]){ + temp = c[j]; + c[j] = c[j+1]; + c[j+1] = temp; + noOfSwaps++; + } + } + } + + cout<<"Array after bubble sorting algorithm: "< +#include + +using namespace std; + +int main(){ + const int arraySize=20; + int c[arraySize] = {}, checker=0, counter=0; + cout<<"Enter 20 integer values between 10 and 100 inclusive: "<>checker; + counter=0; + for (int j=0; j +using namespace std; + +int whatIsThis( int [], int ); // function prototype + +int main() { + const int arraySize = 10; + int a[arraySize] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + int result = whatIsThis(a, arraySize); + cout << "Result is " << result << endl; +} + +int whatIsThis( int b[], int size ){ + if ( size == 1 ) + return b[ 0 ]; + else + return b[ size - 1 ]+whatIsThis( b, size - 1 ); +} diff --git a/Suriya/Assignment4/ex7_24b.cpp b/Suriya/Assignment4/ex7_24b.cpp new file mode 100644 index 0000000..9e004f7 --- /dev/null +++ b/Suriya/Assignment4/ex7_24b.cpp @@ -0,0 +1,47 @@ +//Exercise 7.24(b) + +#include +#include +using namespace std; + +int main(){ + int chess[8][8] = {}; + int horizontal[8] = {2, 1, -1, -2, -2, -1, 1, 2}; + int vertical[8] = {-1, -2, -2, -1, 1, 2, 2, 1}; + int currentRow=3, currentColumn=3; + int expRow=0, expColumn=0; + int breaker=1, breaker1=1; + int noOfMoves=0; + + for (int i=1; i<=64 && breaker1!=0; i++){ + breaker1=0; + breaker=0; + for (int moveNumber=0; moveNumber<8 && breaker==0; moveNumber++){ + expRow = currentRow+vertical[moveNumber]; + expColumn = currentColumn+horizontal[moveNumber]; + if(expRow>7 || expRow<0 || expColumn>7 || expColumn<0 || chess[expRow][expColumn]!=0) + continue; + else { + currentRow = expRow; + currentColumn = expColumn; + breaker = 1; + breaker1++; + } + } + + if(breaker1==0) + break; + + chess[currentRow][currentColumn] = i; + noOfMoves = i; + } + + for (int i=0; i<8; i++){ + for (int j=0; j<8; j++){ + cout< +#include +using namespace std; + +int main(){ + int chess[8][8] = {}; + int horizontal[8] = {2, 1, -1, -2, -2, -1, 1, 2}; + int vertical[8] = {-1, -2, -2, -1, 1, 2, 2, 1}; + int currentRow=3, currentColumn=3; + int expRow=0, expColumn=0; + int finRow=0, finColumn=0; + int breaker=1; + int accessMin; + int noOfMoves=0; + + int accessibility[8][8] = {{2, 3, 4, 4,4, 4, 3, 2 }, + {3, 4, 6, 6,6, 6, 4, 3 }, + {4, 6, 8, 8,8, 8, 6, 4 }, + {4, 6, 8, 8,8, 8, 6, 4 }, + {4, 6, 8, 8,8, 8, 6, 4 }, + {4, 6, 8, 8,8, 8, 6, 4 }, + {3, 4, 6, 6,6, 6, 4, 4 }, + {2, 3, 4, 4,4, 4, 3, 4 }, + }; + + chess[currentRow][currentColumn] = 0; + for (int i=1; i<=64; i++){ + breaker=0; + accessMin=9; + for (int moveNumber=0; moveNumber<8; moveNumber++){ + expRow = currentRow+vertical[moveNumber]; + expColumn = currentColumn+horizontal[moveNumber]; + if(expRow>7 || expRow<0 || expColumn>7 || expColumn<0 || chess[expRow][expColumn]!=0) + continue; + else if(accessibility[expRow][expColumn] +#include +#include +#include + +using namespace std; + +int main(){ + srand(time(0)); + int chess[8][8] = {}; + int horizontal[8] = {2, 1, -1, -2, -2, -1, 1, 2}; + int vertical[8] = {-1, -2, -2, -1, 1, 2, 2, 1}; + int currentRow=3, currentColumn=3; + int expRow=0, expColumn=0; + int breaker1=1; + int noOfMoves=0; + int toMove; + + for (int i = 0; i <= 64; i++) { + for (int moveNumber = 0; moveNumber < 8; moveNumber++) { + expRow = currentRow + vertical[moveNumber]; + expColumn = currentColumn + horizontal[moveNumber]; + if (expRow > 7 || expRow < 0 || expColumn > 7 || expColumn < 0 || chess[expRow][expColumn] != 0) + continue; + else + breaker1 = 1; + } + + if (breaker1 == 0) + break; + + while (breaker1 != 0) { + toMove = rand() % 8; + expRow = currentRow + vertical[toMove]; + expColumn = currentColumn + horizontal[toMove]; + if (expRow > 7 || expRow < 0 || expColumn > 7 || expColumn < 0 || chess[expRow][expColumn] != 0) + continue; + else { + currentRow = expRow; + currentColumn = expColumn; + chess[currentRow][currentColumn] = i; + noOfMoves = i; + breaker1 = 0; + } + } + } + + for (int i=0; i<8; i++){ + for (int j=0; j<8; j++){ + cout< +#include +#include +#include + +using namespace std; + +int main(){ + + int horizontal[8] = {2, 1, -1, -2, -2, -1, 1, 2}; + int vertical[8] = {-1, -2, -2, -1, 1, 2, 2, 1}; + int currentRow=3, currentColumn=3; + int expRow=0, expColumn=0; + int breaker1=1; + int noOfMoves=0; + int toMove; + + int tourArray[1000] = {}; + + for(int k=0; k<1000; k++) { + srand(time(0)); + int chess[8][8] = {}; + noOfMoves = 0; + for (int i = 0; i <= 64; i++) { + for (int moveNumber = 0; moveNumber < 8; moveNumber++) { + expRow = currentRow + vertical[moveNumber]; + expColumn = currentColumn + horizontal[moveNumber]; + if (expRow > 7 || expRow < 0 || expColumn > 7 || expColumn < 0 || chess[expRow][expColumn] != 0) + continue; + else + breaker1 = 1; + } + + if (breaker1 == 0) + break; + + while (breaker1 != 0) { + toMove = rand() % 8; + expRow = currentRow + vertical[toMove]; + expColumn = currentColumn + horizontal[toMove]; + if (expRow > 7 || expRow < 0 || expColumn > 7 || expColumn < 0 || chess[expRow][expColumn] != 0) + continue; + else { + currentRow = expRow; + currentColumn = expColumn; + chess[currentRow][currentColumn] = i; + noOfMoves = i; + breaker1 = 0; + } + } + } + + tourArray[k]=noOfMoves; + } + + cout<<"Length of thousand tours: "< +#include +#include +#include + +using namespace std; + +int main(){ + + int horizontal[8] = {2, 1, -1, -2, -2, -1, 1, 2}; + int vertical[8] = {-1, -2, -2, -1, 1, 2, 2, 1}; + int currentRow=3, currentColumn=3; + int expRow=0, expColumn=0; + int breaker1=1; + int noOfMoves=0; + int counter=0, toMove; + + while(noOfMoves!=64) { + srand(time(0)); + int chess[8][8] = {}; + noOfMoves = 0; + for (int i = 0; i <= 64; i++) { + for (int moveNumber = 0; moveNumber < 8; moveNumber++) { + expRow = currentRow + vertical[moveNumber]; + expColumn = currentColumn + horizontal[moveNumber]; + if (expRow > 7 || expRow < 0 || expColumn > 7 || expColumn < 0 || chess[expRow][expColumn] != 0) + continue; + else + breaker1 = 1; + } + + if (breaker1 == 0) + break; + + while (breaker1 != 0) { + toMove = rand() % 8; + expRow = currentRow + vertical[toMove]; + expColumn = currentColumn + horizontal[toMove]; + if (expRow > 7 || expRow < 0 || expColumn > 7 || expColumn < 0 || chess[expRow][expColumn] != 0) + continue; + else { + currentRow = expRow; + currentColumn = expColumn; + chess[currentRow][currentColumn] = i; + noOfMoves = i; + breaker1 = 0; + } + } + } + counter++; + if (noOfMoves==64){ + for (int i=0; i<8; i++){ + for (int j=0; j<8; j++){ + cout< +#include + +using namespace std; + +int main(){ + const int sieveSize = 1000; + int sieve[sieveSize] = {}; + for (int i=2; i +#include + +using namespace std; + +void bucketSort(int [], int); + +int main(){ + const int sortSize = 10; + int toSort[sortSize] = {94, 3, 76, 35, 100, 1009, 45, 25, 701, 54}; + + cout<<"Array before sorting: "<largestNumber) + largestNumber=toSort[p]; + } + + int dummy=largestNumber, noOfDigits = 0; + do{ + noOfDigits++; + dummy = dummy/10; + }while (dummy!=0); + + for (int i=1; i<=noOfDigits; i++) + bucketSort(toSort, sortSize); + + cout<<"Array after sorting: "< + +using namespace std; + +void selectionSort(int [], int); + +int main(){ + const int sortSize = 10; + int toSort[sortSize] = {94, 3, 76, 35, 100, 1009, 45, 25, 701, 54}; + + cout<<"Array before sorting: "< +using namespace std; + +int linearSearch( const int [], int, int ); + +int main() +{ + const int arraySize = 100; + int a[ arraySize ]; + int searchKey; + + for ( int i = 0; i < arraySize; ++i ) + a[ i ] = 2 * i; // + + cout << "Enter integer search key: "; + cin >> searchKey; + + int element = linearSearch( a, searchKey, arraySize ); + + if ( element != -1 ) + cout << "Found value in element " << element << endl; + else + cout << "Value not found" << endl; +} + +int linearSearch( const int array[], int key, int sizeOfArray) +{ + if (sizeOfArray==0){ + if (array[sizeOfArray]==key) + return 0; + else + return -1; + } + if (array[sizeOfArray-1]==key) + return sizeOfArray-1; + else + return linearSearch(array, key, sizeOfArray-1); +} \ No newline at end of file diff --git a/Suriya/Assignment4/ex7_37.cpp b/Suriya/Assignment4/ex7_37.cpp new file mode 100644 index 0000000..e78f6ee --- /dev/null +++ b/Suriya/Assignment4/ex7_37.cpp @@ -0,0 +1,27 @@ +//Exercise 7.37 + +#include +using namespace std; + +int recursiveMinimum(const int[], int, int); + +int main(){ + const int arraySize = 10; + int array[arraySize] = {94, 3, 76, 35, 100, 1009, 45, 1, 701, 54}; + + cout<<"The minimum value found in the array: "<=array[end]) + return recursiveMinimum(array, start+1, end); + if(array[start] +#include + +using namespace std; + +int recursiveMinimum(const vector&, int, int); + +int main(){ + vector array{94, 3, 76, 35, 100, 1009, 45, 1, 701, 54}; + + cout<<"The minimum value found in the array: "<&array, int start, int end){ + if (start==end){ + return array[start]; + } + + else{ + if(array[start]>=array[end]) + return recursiveMinimum(array, start+1, end); + if(array[start] +using namespace std; + +int main(){ + //a) the pointer variable 'number' points towards an arbitrary variable. + //it has to be initialised to zero or some variable of 'int' data type + + int *number=0; + cout << *number < + +using namespace std; + +void mystery1( char *, const char * ); + +int main(){ + char string1[ 80 ]; + char string2[ 80 ]; + cout << "Enter two strings: "; + cin >> string1 >> string2; + mystery1( string1, string2 ); + cout << string1 << endl; +} + +//The function appends string 2 to the end of string 1 +//Two pointers pointing to the first elements of each string are initialised here +void mystery1( char *s1, const char *s2 ){ + //the while loop increments the pointer s1 till it points the last non-'/0' element of the first string + while ( *s1 != '\0' ) + ++s1; + + //the for loop copies each element from s2 to the tail of s1 + for ( ; *s1 = *s2; ++s1, ++s2 ); +} diff --git a/Suriya/Assignment5/ex8_14.cpp b/Suriya/Assignment5/ex8_14.cpp new file mode 100644 index 0000000..d3f1f5b --- /dev/null +++ b/Suriya/Assignment5/ex8_14.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; + +int mystery2( const char * ); + +int main() +{ + char string1[ 80 ]; + cout << "Enter a string: "; + cin >> string1; + cout << mystery2( string1 ) << endl; +} + +// The function returns the length of the string +int mystery2( const char *s ){ + int x; + //for loop increments x till it encounters '/0' character + for ( x = 0; *s != '\0'; ++s ) + ++x; + + return x; +} diff --git a/Suriya/Assignment5/ex8_15.cpp b/Suriya/Assignment5/ex8_15.cpp new file mode 100644 index 0000000..15c2ec8 --- /dev/null +++ b/Suriya/Assignment5/ex8_15.cpp @@ -0,0 +1,58 @@ +//Exercise 8.15 + +#include +using namespace std; + +void swapElements (int * , int *); +void quickSort(int [], const int, const int); + +int main(){ + const int arraySize = 10; + int toSort[arraySize] = {37, 2, 6, 4, 89, 8, 10, 12, 68, 45 }; + + cout<<"Array before sorting: "<=2) { + int j = start; + int k = end + 1; + int currentPosition = j; + + while (j <= k + 1 && k >= j + 1) { + for (k = k - 1; k > j; k--) { + if (toSort[k] < toSort[j]) { + swapElements(&toSort[k], &toSort[j]); + currentPosition = k; + break; + } + } + for (j = j + 1; j < k; j++) { + if (toSort[j] > toSort[k]) { + swapElements(&toSort[j], &toSort[k]); + currentPosition = j; + break; + } + } + } + quickSort(toSort, start, currentPosition - 1); + quickSort(toSort, currentPosition + 1, end); + } +} + +void swapElements(int *const location1, int *const location2){ + int temp = *location1; + *location1 = *location2; + *location2 = temp; +} \ No newline at end of file diff --git a/Suriya/Assignment5/ex8_16.cpp b/Suriya/Assignment5/ex8_16.cpp new file mode 100644 index 0000000..bf2a714 --- /dev/null +++ b/Suriya/Assignment5/ex8_16.cpp @@ -0,0 +1,56 @@ +//Exercise 8.16 + +#include +#include +using namespace std; + +void mazeGenerator(char [12][12], int row, int column); + +int main(){ + char maze[12][12] = { {'#','#','#','#','#','#','#','#','#','#','#','#'}, + {'#','.','.','.','#','.','.','.','.','.','.','#'}, + {'.','.','#','.','#','.','#','#','#','#','.','#'}, + {'#','#','#','.','#','.','.','.','.','#','.','#'}, + {'#','.','.','.','.','#','#','#','.','#','.','o'}, + {'#','#','#','#','.','#','.','#','.','#','.','#'}, + {'#','.','.','#','.','#','.','#','.','#','.','#'}, + {'#','#','.','#','.','#','.','#','.','#','.','#'}, + {'#','.','.','.','.','.','.','.','.','#','.','#'}, + {'#','#','#','#','#','#','.','#','#','#','.','#'}, + {'#','.','.','.','.','.','.','#','.','.','.','#'}, + {'#','#','#','#','#','#','#','#','#','#','#','#'}, + }; + + mazeGenerator(maze, 2, 0); + +} + +void mazeGenerator(char maze[12][12], int row, int column){ + if (maze[row][column] == 'o') + cout<<"\n The maze is solved!"< +#include + +using namespace std; + +int main(){ + unsigned int values[5] = { 2, 4, 6, 8, 10}; + unsigned int *vPtr; + + cout<<"Array elements printed using index notation"< +#include +using namespace std; + +GaussSolver::GaussSolver(denArray A, denArray b){ + if ((A.getRowDim() == b.getRowDim()) && (b.getColDim() == 1) ){ + soln = denArray(A.getColDim(),1); + K = denArray(A.getRowDim(),A.getColDim()); + copy(A,K); + f = denArray(b.getRowDim(),b.getColDim()); + copy(b,f); + solve(K,f); + } + + else + cout<<"Invalid matrix dimensions"<= 1e-6) { + multiplier = *(kPtr + i * column + i) / *(kPtr + k * column + i); + for (int j = i; j < column; j++) { + *(kPtr + k * column + j) = (*(kPtr + k * column + j)) * multiplier + - *(kPtr + i * column + j); + } + *(fPtr + k) = (*(fPtr + k)) * multiplier - (*(fPtr + i)); + } + + else { + *(kPtr + k * column + i) = 0; + continue; + } + } + } + + //backward substitution + for (int i = (column-1); i>0; i--){ + for (int k = i-1; k>=0; k--){ + if (abs(*(kPtr + k * column + i)) >= 1e-6) { + multiplier = *(kPtr + k * column + i) / *(kPtr + i * column + i); + *(kPtr + k * column + i) = 0; + *(fPtr + k) = (*(fPtr + k)) - (*(fPtr + i)) * multiplier; + } + else { + *(kPtr + k * column + i) = 0; + continue; + } + } + } + + double * solnPtr = soln.getArray(); + for (int l = 0; l +#include +#include + +using namespace std; + +IterSolver::IterSolver(denArray A, denArray b, double tol){ + if ((A.getRowDim() == b.getRowDim()) && (b.getColDim() == 1) ){ + tolerance = tol; + soln = denArray(A.getColDim(),1); + residual = denArray(b.getRowDim(),1); + direction = denArray(b.getRowDim(),1); + K = denArray(A.getRowDim(),A.getColDim()); + copy(A,K); + f = denArray(b.getRowDim(),b.getColDim()); + copy(b,f); + solve(K,f); + } + + else + cout<<"Invalid matrix dimensions"<=tolerance){ + loopCounter++; + + //Calculation of beta + rNrN_prev = rNrN; + transpose(residual, residualTrans); + rTr = denArrayProd(residualTrans, residual); + rNrN = *(rTr.getArray()); + beta = rNrN / rNrN_prev; + + //Search direction + for (int j=0; j +#include +#include +#include "denArray.h" + +using namespace std; + +denArray::denArray (int row, int column){ + setArrayDim(row,column); +} + +void denArray::setArrayDim(int row,int column){ + row_dim = row; + column_dim = column; + arr = new double[row_dim * column_dim]; +} + +int denArray::getRowDim(){ + return row_dim; +} + +int denArray::getColDim(){ + return column_dim; +} + +int denArray::getLength(){ + return row_dim * column_dim; +} + +double * denArray::getArray(){ + return arr; +} + +void denArray::setArray(){ + cout<<"Enter "<< row_dim*column_dim << " numbers:" << endl; + for (int i = 0; i < row_dim; i++) { + for (int j = 0; j < column_dim; j++) { + cin >> *(arr + i * column_dim + j); + } + } +} + +void denArray::declareArray(const double *declare, const int size) { + int counter = 0; + for (int i = 0; i < row_dim; i++) { + for (int j = 0; j < column_dim; j++) { + if (countermax) + max = abs(*(arr + i * column_dim + j)); + } + } + return max; +} \ No newline at end of file diff --git a/Suriya/MidtermProject/DenArray Class/denArray.h b/Suriya/MidtermProject/DenArray Class/denArray.h new file mode 100644 index 0000000..28eac79 --- /dev/null +++ b/Suriya/MidtermProject/DenArray Class/denArray.h @@ -0,0 +1,88 @@ + + +class denArray{ + public: + denArray(int, int); + void setArrayDim(int, int); + int getRowDim(); + int getColDim(); + int getLength(); + double * getArray(); + void setArray(); + void declareArray(const double *,const int); + void printArray(); + double lNorm(int); + double l2Norm(); + double infNorm(); + + private: + int row_dim; + int column_dim; + double * arr; +}; + +class denArrayProd { +public: + denArrayProd(denArray, denArray); + void product(denArray, denArray); + void printArray(); + int getRowDim(); + int getColDim(); + int getLength(); + double * getArray(); + double lNorm(int); + double l2Norm(); + double infNorm(); + + +private: + denArray prod = denArray(0,0); +}; + +class GaussSolver { +public: + GaussSolver(denArray, denArray); + void solve(denArray, denArray); + void copy(denArray, denArray); + void printArray(); + int getRowDim(); + int getColDim(); + int getLength(); + double * getArray(); + double lNorm(int); + double l2Norm(); + double infNorm(); + +private: + denArray K = denArray(0,0); + denArray f = denArray(0,0); + denArray soln = denArray(0,0); +}; + +class IterSolver { +public: + IterSolver(denArray, denArray, double); + void solve(denArray, denArray); + void copy(denArray, denArray); + void transpose(denArray, denArray); + void printArray(); + int getRowDim(); + int getColDim(); + int getLength(); + double * getArray(); + double lNorm(int); + double l2Norm(); + double infNorm(); + +private: + denArray soln = denArray(0,0); + denArray residual = denArray(0,0); + denArray K = denArray(0,0); + denArray f = denArray(0,0); + denArray direction = denArray(0,0); + double tolerance; + double epsilon; + double alpha; + double beta; + +}; \ No newline at end of file diff --git a/Suriya/MidtermProject/DenArray Class/denArrayProd.cpp b/Suriya/MidtermProject/DenArray Class/denArrayProd.cpp new file mode 100644 index 0000000..dc2fe97 --- /dev/null +++ b/Suriya/MidtermProject/DenArray Class/denArrayProd.cpp @@ -0,0 +1,66 @@ +#include "denArray.h" +#include +using namespace std; + +denArrayProd::denArrayProd(denArray A, denArray B) { + if (A.getColDim() == B.getRowDim()){ + prod = denArray(A.getRowDim(), B.getColDim()); + product(A,B); + } + + else + cout<<"Array dimensions do not conform for matrix multiplication"< +#include "denArray.h" + +using namespace std; + +int main() { + + denArray A = denArray(3,2); + double a[6] = {1, 0, 3, 0, 5, 0}; + A.declareArray(a,6); + cout<<"Matrix A is: "< +using namespace std; + +GaussSolver::GaussSolver(SparArray A, SparArray b){ + if ((A.getRowDim() == b.getRowDim()) && (b.getColDim() == 1) ){ + soln = SparArray(A.getColDim(),1); + solve(A,b); + } + + else + cout<<"Invalid matrix dimensions"<= 1e-6) { + multiplier = *(aNew + i * col + i) / *(aNew + k * col + i); + for (int j = i; j < col; j++) { + *(aNew + k * col + j) = (*(aNew + k * col + j)) * multiplier + - *(aNew + i * col + j); + } + *(bNew + k) = (*(bNew + k)) * multiplier - (*(bNew + i)); + } + + else { + *(aNew + k * col + i) = 0; + continue; + } + } + } + + //backward substitution + for (int i = (col-1); i>0; i--){ + for (int k = i-1; k>=0; k--){ + if (abs(*(aNew + k * col + i)) >= 1e-6) { + multiplier = *(aNew + k * col + i) / *(aNew + i * col + i); + *(aNew + k * col + i) = 0; + *(bNew + k) = (*(bNew + k)) - (*(bNew + i)) * multiplier; + } + else { + *(aNew + k * col + i) = 0; + continue; + } + } + } + + for (int l = 0; l +#include +#include +using namespace std; + +IterSolver::IterSolver(SparArray A, SparArray b, double tol){ + if ((A.getRowDim() == b.getRowDim()) && (b.getColDim() == 1) ){ + tolerance = tol; + soln = SparArray(A.getColDim(),1); + solve(A,b,tolerance); + } + + else + cout<<"Invalid matrix dimensions"<=tolerance) { + loopCounter++; + + //Calculation of beta + rNrN_prev = rNrN; + l2Cal.declareArray(residual,row); + rNrN = pow(l2Cal.l2Norm(),2); + beta = rNrN / rNrN_prev; + + //Search Direction + for (int j=0; j +#include +#include + +using namespace std; + +SparArray::SparArray(int row, int column){ + setArrayDim(row, column); +} + +void SparArray::setArrayDim(int row, int column) { + row_dim = row; + column_dim = column; + size = 0; +} + +void SparArray::setArray() { + size = 0; + cout<<"Enter "<< row_dim*column_dim << " numbers:" << endl; + double *tempArr = new double [row_dim * column_dim]; + for (int i = 0; i < row_dim; i++) { + for (int j = 0; j < column_dim; j++) { + cin >> *(tempArr + i * column_dim + j); + if (*(tempArr + i * column_dim + j)!=0) + size++; + } + } + + if (size>0) { + rowPtr = new int[size]; + columnPtr = new int[size]; + valuePtr = new double[size]; + + *spar = rowPtr; + *(spar+1) = columnPtr; + *(spar+2) = valuePtr; + + int counter = 0; + for (int i = 0; i < row_dim; i++) { + for (int j = 0; j < column_dim; j++) { + if (*(tempArr + i * column_dim + j) != 0) { + *(rowPtr + counter) = i; + *(columnPtr + counter) = j; + *(valuePtr + counter) = *(tempArr + i * column_dim + j); + counter++; + } + } + } + } + + if (size==0){ + size = 1; + rowPtr = new int [size]; + columnPtr = new int [size]; + valuePtr = new double [size]; + *(rowPtr) = 0; + *(columnPtr) = 0; + *(valuePtr) = *(tempArr); + } + + delete [] tempArr; +} + +void SparArray::declareArray(const double * declare, int arrSize) { + if (arrSize>1) + { + size = 0; + for (int i = 0; i < arrSize; i++) { + if (*(declare + i) != 0) + size++; + } + + rowPtr = new int[size]; + columnPtr = new int[size]; + valuePtr = new double[size]; + + *spar = rowPtr; + *(spar+1) = columnPtr; + *(spar+2) = valuePtr; + + int counter = 0; + int counter2 = 0; + for (int i = 0; i < row_dim && counter2 < arrSize; i++) { + for (int j = 0; j < column_dim && counter2 < arrSize; j++) { + if (*(declare + i * column_dim + j) != 0) { + *(rowPtr + counter) = i; + *(columnPtr + counter) = j; + *(valuePtr + counter) = *(declare + i * column_dim + j); + counter++; + } + counter2++; + } + } + } + + else if(arrSize == 1){ + size = 1; + rowPtr = new int [size]; + columnPtr = new int [size]; + valuePtr = new double [size]; + *(rowPtr) = 0; + *(columnPtr) = 0; + *(valuePtr) = *(declare); + } +} + +void SparArray::printArray(){ + + int counter = 0; + for (int i=0; i < row_dim; i++){ + for (int j=0; j < column_dim; j++){ + if (*(rowPtr + counter)==i && *(columnPtr + counter)==j){ + cout< max) + max = abs(*(valuePtr + i)); + } + return max; +} + +double SparArray::getValue(int row_index, int col_index) { + if (row_index col_index) + break; + + if (*(rowPtr+counter) > row_index) + break; + } + + return temp; + } + + else + cout<<"Atleast one of the indices exceeds the matrix limit"< +using namespace std; + +SparArrayProd::SparArrayProd(SparArray A, SparArray B) { + if (A.getColDim() == B.getRowDim()){ + prod = SparArray(A.getRowDim(), B.getColDim()); + product(A,B); + } + + else + cout<<"Array dimensions do not conform for matrix multiplication"< +#include "SparArray.h" +using namespace std; + +int main() { + SparArray A = SparArray(3, 2); + double a[6] = {1, 0, 3, 0, 5, 0}; + A.declareArray(a, 6); + cout << "Matrix A is: " << endl; + A.printArray(); + cout<