From ab0fda5adfaaad1e0b2a86fdc515e2ab68e33f9f Mon Sep 17 00:00:00 2001 From: Iresh Eranga Date: Tue, 16 May 2023 09:26:08 +0530 Subject: [PATCH] h --- .../Lab-2023-March/02/Lab-02-exe-02.cpp | 38 +++++++ .../Lab-2023-March/02/Lab-02-exe01.cpp | 95 ++++++++++++++++++ .../Labsheet - 02.pdf => 02/Lab-02.pdf} | Bin .../Lab-2023-March/Lab-02/ex-01-shanelka.cpp | 59 ----------- .../Lab-2023-March/Lab-02/ex-02-shanelka.cpp | 34 ------- 5 files changed, 133 insertions(+), 93 deletions(-) create mode 100644 Lab Exercises/Lab-2023-March/02/Lab-02-exe-02.cpp create mode 100644 Lab Exercises/Lab-2023-March/02/Lab-02-exe01.cpp rename Lab Exercises/Lab-2023-March/{Lab-02/Labsheet - 02.pdf => 02/Lab-02.pdf} (100%) delete mode 100644 Lab Exercises/Lab-2023-March/Lab-02/ex-01-shanelka.cpp delete mode 100644 Lab Exercises/Lab-2023-March/Lab-02/ex-02-shanelka.cpp diff --git a/Lab Exercises/Lab-2023-March/02/Lab-02-exe-02.cpp b/Lab Exercises/Lab-2023-March/02/Lab-02-exe-02.cpp new file mode 100644 index 0000000..5103989 --- /dev/null +++ b/Lab Exercises/Lab-2023-March/02/Lab-02-exe-02.cpp @@ -0,0 +1,38 @@ +#include + +using namespace std; + +//Structure for rectangle +struct Rectangle { + int length; + int width; +}; + +int area(int length, int width); //function prototype + +int main() +{ + Rectangle house{}; //create variables from Rectangle structure + Rectangle yard{}; + + cout << "Enter length of house :"; //get user inputs + cin >> house.length; + + cout << "Enter width of house :"; + cin >> house.width; + + cout << "Enter length of yard :"; + cin >> yard.length; + + cout << "Enter width of yard :"; + cin >> yard.width; + + cout << "Area of house : " << area(house.length, house.width) << endl; + cout << "Area of yard : " << area(yard.length, yard.width) << endl; + cout << "Area of green color area : " << area(yard.length, yard.width) - area(house.length, house.width) << endl; +} + +int area(int length, int width) +{ + return length * width; +} \ No newline at end of file diff --git a/Lab Exercises/Lab-2023-March/02/Lab-02-exe01.cpp b/Lab Exercises/Lab-2023-March/02/Lab-02-exe01.cpp new file mode 100644 index 0000000..c222812 --- /dev/null +++ b/Lab Exercises/Lab-2023-March/02/Lab-02-exe01.cpp @@ -0,0 +1,95 @@ +// Lab-02-exe01.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +using namespace std; + +int searchKey(int number, int numbers[10]); //function prototype +void findMax(int numbers[10]); + +int main() //main function begin +{ + int numbers[10]; //array + int i; + int number; + + for (i = 0;i < 10;i++) + { + cout << "Enter " << i + 1 << " Number :"; + cin >> numbers[i]; + } + cout << endl; + + cout << "Enter search number :"; //get user input to find integer + cin >> number; + + cout << endl; + + searchKey(number,numbers); //call the function + findMax(numbers); //call the function max number + return 0; +} //end of the main function + +int searchKey(int number, int numbers[10]) +{ + int i,j; + + for (i = 0;i < 10;i++) + { + if (numbers[i] == number) + { + j = 1; + break; + } + else + { + j = 0; + } + } + + if (j == 0) + { + cout << "value Not Found" << endl<= maxn) + { + maxn = numbers[i]; + } + } + + cout <<"Max number is : " << maxn << endl; + + return ; +} + + + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/Lab Exercises/Lab-2023-March/Lab-02/Labsheet - 02.pdf b/Lab Exercises/Lab-2023-March/02/Lab-02.pdf similarity index 100% rename from Lab Exercises/Lab-2023-March/Lab-02/Labsheet - 02.pdf rename to Lab Exercises/Lab-2023-March/02/Lab-02.pdf diff --git a/Lab Exercises/Lab-2023-March/Lab-02/ex-01-shanelka.cpp b/Lab Exercises/Lab-2023-March/Lab-02/ex-01-shanelka.cpp deleted file mode 100644 index 894bf47..0000000 --- a/Lab Exercises/Lab-2023-March/Lab-02/ex-01-shanelka.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include - -// function prototype - -int searchKey(int x, int numbers[]); -int findMax(int numbers[]); - -int main() { - int numbers[10], number; - int i; // counter variable - - // get inputs from keyboard - for (i = 0; i < 10; i++) { - std::cout << "Enter number " << i + 1 << " : "; - std::cin >> numbers[i]; - } - - std::cout << std::endl << "Enter number for search : "; - std::cin >> number; - - if (searchKey(number, numbers) != -1) { - std::cout << "Index is " << searchKey(number, numbers) << std::endl; - } - else { - std::cout << "Value not found"; - } - - std::cout << "Maximum number is " << findMax(numbers) << std::endl; - - return 0; -} - -// function definition - -int searchKey(int x, int numbers[]) { - int i; // counter variable - int status = -1; // for search return status - - for (i = 0; i < 10; i++) { - if (x == numbers[i]) { - status = i; - } - } - - return status; -} - -int findMax(int numbers[]) { - int max = numbers[0]; - int i; - - for (i = 0; i < 10; i++) { - if (max < numbers[i]) { - max = numbers[i]; - } - } - - return max; -} \ No newline at end of file diff --git a/Lab Exercises/Lab-2023-March/Lab-02/ex-02-shanelka.cpp b/Lab Exercises/Lab-2023-March/Lab-02/ex-02-shanelka.cpp deleted file mode 100644 index e75a7a1..0000000 --- a/Lab Exercises/Lab-2023-March/Lab-02/ex-02-shanelka.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include - -// create a structure -struct Rectangle { - int length; - int width; -}; - -// function prototype -int area(int length, int width); - -// start the main function -int main() { - Rectangle yard, house; // create variables with structure - - std::cout << "Enter length of yard : "; - std::cin >> yard.length; - std::cout << "Enter width of yard : "; - std::cin >> yard.width; - - std::cout << "Enter length of house : "; - std::cin >> house.length; - std::cout << "Enter width of house : "; - std::cin >> house.width; - - std::cout << "\nLawn area = " << area(yard.length, yard.width) - area(house.length, house.width) << std::endl; - - return 0; -} - -// function definition -int area(int length, int width) { - return length * width; -} \ No newline at end of file