Answer:
a) # include <iostream>
# include <conio.h>
# include <stdio.h>
# include <string.h>
using namespace::std;
bool IsPalindrome(const string& str)
{
if (str.empty())
return false;
int i = 0; // first characters
int j = str.length() - 1; // last character
while (i < j)
{
if (str[i] != str[j])
{
return false;
}
i++;
j--;
}
return true;
}
int main()
{
string str;
cout<<"Enter the string";
getline(cin, str);
bool a= IsPalindrome(str);
if(a)
{
cout<<"Is in palindrome";
}
else
{
cout<<"Is not in palindrome";
}
}
b) Modified version of function with full program to discard uppercase or lowercase is as below:
# include <iostream>
# include <conio.h>
# include <stdio.h>
# include <string.h>
using namespace::std;
bool IsPalindrome(const string& str)
{
if (str.empty())
return false;
int i = 0; // first characters
int j = str.length() - 1; // last character
while (i < j)
{
char a= tolower(str[i]);
char b= tolower(str[j]);
if (a != b)
{
return false;
}
i++;
j--;
}
return true;
}
int main()
{
string str;
cout<<"Enter the string";
getline(cin, str);
bool a= IsPalindrome(str);
if(a)
{
cout<<"Is in palindrome";
}
else
{
cout<<"Is not in palindrome";
}
}
Explanation:
Please check the answer section.
Answer:
The corrected question is:
Write an SQL statement to display the WarehouseID, the sum of QuantityOnOrder and sum of QuantityOnHand, grouped by WarehouseID and QuantityOnOrder. Name the sum of QuantityOnOrder as TotalItemsOnOrder and the sum of QuantityOnHand as TotalItemsOnHand. Use only the INVENTORY table in your SQL statement.
Answer to this corrected question:
SELECT WarehouseID,
SUM(QuantityOnOrder) AS TotalItemsOnOrder,
SUM(QuantityOnHand) AS TotalItemsOnHand
FROM INVENTORY
GROUP BY WarehouseID, QuantityOnOrder;
According to the given question:
SELECT WarehouseID,
SUM(QuantityOnOrder) + SUM(QuantityOnHand) AS TotalItemsOnHand
FROM INVENTORY
GROUP BY WarehouseID, QuantityOnOrder;
Explanation:
- In the SQL statement SELECT statement is used to select the data from the table. Here the SELECT statement is used to select WarehouseID, Sum of the columns QuantityOnOrder and QuantityOnHand from INVENTORY table.
- The sum of QuantityOnOrder and QuantityOnHand columns are given the name of TotalItemsonHand (In case of the corrected question the sum of column QuantityOnOrder is named as TotalItemsOnOrder and the column QuantityOnHand is named as TotalItemsOnHand
) using Alias AS. Alias is the temporary name given to the columns or table to make them more readable.
- GROUP BY statement is used to arrange or "group" same data and is often use with aggregate functions like SUM function here. So the grouping here is done based on two columns WarehouseID and QuantityOnOrder.
- SUM function in this SQL statement is an aggregate function to calculate the sum of all value in the columns QuantityOnOrder and QuantityOnHand.
Answer:
a. GoBackN:
A sends 9 segments in total. They are initially sent segments 1, 2, 3, 4, 5 and later re-sent segments 2, 3, 4, and 5. B sends 8 ACKs. They are 4 ACKS with sequence number 1, and 4 ACKS with sequence numbers 2, 3, 4, and 5.
Selective Repeat:
A sends 6 segments in total. They are initially sent segments 1, 2, 3, 4, 5 and later re-sent segments 2. B sends 5 ACKs. They are 4 ACKS with sequence number 1, 3, 4, 5. And there is one ACK with sequence number 2.
TCP:
A sends 6 segments in total. They are initially sent segments 1, 2, 3, 4, 5 and later re-sent segments 2. B sends 5 ACKs. They are 4 ACKS with sequence number 2. There is one ACK with sequence numbers 6. Note that TCP always send an ACK with expected sequence number.
TCP successfully delivers all five data segments in shortest time interval. This is because TCP uses fast retransmit without waiting until time out.
Explanation:
Answer:
7
Explanation:
Given the codes as follows:
- j = i = 1
- i += j + j * 5
- print("What is i?", i)
In line 1, the value of 1 is assigned to variable i and then the variable i is assigned to variable j. This means j will hold the value of 1 as well.
In line 2, j will be multiplied with 5 prior to the addition with j itself. So, j + j * 5 -> 1 + (1 * 5) -> 1 + 5 -> 6
Next, value of 6 will be added with i. i = i + 6 -> i = 1 + 6 -> 7#
Eventually, value of 7 will be printed out (Line 3).