Page 1 of 1

Supplementary Assignment Release time Sunday, 21 Nov2021 at 12:00AM Due date Thursday, 25Nov2021 at 11:59PM This assignm

Posted: Sat Nov 27, 2021 2:43 pm
by answerhappygod
Supplementary Assignment Release Time Sunday 21 Nov2021 At 12 00am Due Date Thursday 25nov2021 At 11 59pm This Assignm 1
Supplementary Assignment Release Time Sunday 21 Nov2021 At 12 00am Due Date Thursday 25nov2021 At 11 59pm This Assignm 1 (192.4 KiB) Viewed 51 times
Supplementary Assignment Release time Sunday, 21 Nov2021 at 12:00AM Due date Thursday, 25Nov2021 at 11:59PM This assignment is a supplementary and is released for students who want to recover their middle term exam low grade. This assignment worth 5 marks and it is to be added to your final marks. The implementation of your code must be correct and satisfy the description given below to get the full marks. Problem A customer would like to buy a car when he/she is given a list of car prices as an array of integers. The customer would like to be able to query the find the order of lowest price as he/she prefers. array and You must define the function that helps the customer to achieve this goal. Examples Assume that the customer is given the following array of prices: { 25000, 20000, 29499, 10000, 20000, 15000, 25000, 20000 }, then, 1. If the customer wants the second lowest price, then the function must return the price 15000 2. If the customer wants the fourth lowest price, then the function must return the price 25000. Note that 20000 (which is the third lowest price) is considered only once. 3. If the customer wants the first lowest price, then the function must return the price 10000 Method signature int lowestPrice(int prices[], int size, int order); Where: prices: array that represents the prices of cars. Same prices can appear more than once. size: the size of the array prices. If the size is less than or equal to zero, then the function must return -1. order: the order that the customer wants. If the order is out-of-range of the array prices or invalid (ie. less than zero), then the function must return -1.
Test Cases Test 1 prices: (25000, 20000, 29499, 10000, 20000, 29000, 25000, 20000, 25000, 10000}, size: 10, order: 3 Returned result must be: 25000 Test 2 prices: (25000, 20000, 29499, 10000, 20000, 29000, 25000, 20000, 25000, 10000}, size: 10, order: 5 Returned result must be: 29499 Test 3 prices: <25000, 20000, 29499, 10000, 20000, 29000, 25000, 20000, 25000, 10000}, size: 10, order: 4 Returned result must be: 29000 Test 4 prices: (25000, 20000, 29499, 10000, 20000, 29000, 25000, 20000, 25000, 10000}, size: 10, order: 7 Returned result must be: -1 (there is no 7th lowest price. There are only 5 prices available) Test 5 prices: (25000, 20000}, size: 2, order: 2 Returned result must be: 25000 . Test 6 prices: (25000, 20000), size: 2, order: 3 Returned result must be: -1 (there are only 2 prices, and therefore, there is no 3rd lowest price) Test 7 prices: <20000}, size: 1, order: 1 Returned result must be: 20000 Test 8 prices: {10000, 20000, 25000, 29499}, size: 4, order: 2 Returned result must be: 20000 Test 9 prices: {10000, 20000, 25000, 29499}, size: 4, order: -5 Returned result must be: -1 (the order is not valid, and therefore, unable to find a lowest price)
#include<stdio.h> #include "PUT_YOUR_STUDENT_ID_HERE.h" // your file must be named as such and exsits in same folder of this file void oracle(int no, int array[], int size, int order, int expected, int actual) { printf("Test $d: \n\t\tPrices: {",no); for (int i = 0; i < size; i++) { printf(" %d ", array); } printf("}\n\t\tOrder: %d", order); printf("\n\t\tExpected result: %d", expected); printf("\n\t\tYour function result: %d", actual); printf("\n\t\tStatus: %s\n", expected==actual?"passed":"failed"); } , 25000 10000); int main() { 11 oracles int tests = 0; int testAl[ ] = { 25000, 20000, 29499, 10000, 20000, 29000, 25000, 20000 int orderl = 3; int resl = 25000; int resA = lowestPrice(testAl,sizeof(testAl)/sizeof(int), orderl); oracle(1, testAl, sizeof(testAl)/sizeof(int), orderl, resl, resA); if(res le=resA) tests++; 25000, 10000 }; int testA2[] = { 25000, 20000, 29499, 10000, 20000, 29000, 25000, 20000 int order2 = 5; int res2 = 29499; resA = lowestPrice(testA2, sizeof(testA2)/sizeof(int), order2); oracle(2, testA2, sizeof(testA2)/sizeof(int),order2, res2, resA); if(res2==resA) tests++; int testA3[] = { 25000, 20000, 29499, 10000, 20000, 29000, 25000, 20000 ,25000, 10000 }; int order3 = 4; int res3 = 29000; resA = lowestPrice(testA3, sizeof(testA3)/sizeof(int), order3); oracle(3, testA3, sizeof(testA3)/sizeof(int),order3, res3, resA); if (res 3==resA) tests++; int testA4[] = { 25000, 20000, 29499, 10000, 20000, 29000, 25000, 20000 ,25000, 10000 }; int order4 = 7; int res4 = -1; resA = lowestPrice(testA4, sizeof(testA4)/sizeof(int), order4); oracle(4, testA4, sizeof(testA4)/sizeof(int),order4, res4, resA); if(res4==resA) tests++; int testA5() = {25000, 20000}; int order5 = 2; int res5 = 25000; resA = lowestPrice(testA5, sizeof(testА5)/sizeof(int),order5); oracle(5, testA5, sizeof(testА5)/sizeof(int),order5, res5, resA); if (res 5==resA) tests++; int testA6[] = {25000, 20000}; int order6 = 3;
= int testA7[] {20000}; int order7 = 1; int res7 = 20000; resA = lowestPrice(testA7, sizeof(testA7)/sizeof(int), order7); oracle (7, testA7, sizeof(testA7)/sizeof(int),order7, res7, resA); if(res 7==resA) tests++; int testA8[] {10000, 20000, 25000, 29499}; int order8 = 2; int res8 = 20000; resA = lowestPrice(testA8, sizeof(testA8)/sizeof(int), order8); oracle(8, testA8, sizeof(testA8)/sizeof(int),order8, res8, resA); if(res8==resA) tests++; int testA9[ ] = {10000, 20000, 25000, 29499}; int order9 = -5; int res9 = -1; resA = lowestPrice(testA9, sizeof(testA9)/sizeof(int),order9); oracle(9, testA9, sizeof(testA9)/sizeof(int),order9, res9, resA); if(res 9==resA) tests++; if(tests!=9) printf("\nYour implementation failed %d test(s).\n\n", (9-tests)); else printf ("Your implementation passed all tests. Excellent work.\n\n"); return 0; }
int lowestPrice (int prices[], int size, int order) { // write you code and implementation here } void myHelpFunction1(int param1) { } int myHelpFunction2 (int paramx) { return 0; }