BEST代写-线上留学生作业代写 & 论文代写专家

成立于2015年的老牌留学生代写品牌-BEST代写提供超过百门冷热门留学学科的作业和论文代写服务。全网BEST原创,高质,准时的留学生代写。

C++代写|C-Style Programming Assignment Problem Sheet 1

C++代写|C-Style Programming Assignment Problem Sheet 1

这是一个C++编程作业代写

PROBLEM 1

C-style iteration over arrays and containers is prone to indexing errors and is also tedious to type. You should know
how to eliminate these errors, and make your code more readable using modern C++ styles. Convert the old style
code below to use range-based for loops with the Standard Library containers and raw arrays. You should solve any
runtime errors, intialize with a for loop,and prefer constexpr variables for compile-time constants.

#define SIZE 21 // C-style
std::vector<int> v{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 };
// C-style
for (int i = 0; i < v.size(); ++i)
{
std::cout << v[i];
} i
nt* arr = new int[SIZE];
for (int i = 0; i < SIZE; ++i) {
arr[i] = v.at(i);
std::cout << arr[i];
}

PROBLEM 2

Write a program which asks the user for 2 integers on the command line. Given the two integers a and b, write a
function called MultiplyError to find whether their product (a x b) exceeds the signed 64 bit integer or not. If it
exceeds print Yes else print No. Approach :

  • If either of the number is 0, then it will never exceed the range.
  • Else if the product of the two divided by one equals the other, then also it will be in range.
  • In any other case overflow will occur.

PROBLEM 3

Write a program which asks the user for 10 integers on the command line. The program should create a quickSort
function to sort the integers. The key process in quickSort is the partition() process. The aim of the partition()
function is to receive an array and an element x of the array as a pivot, put x at its correct position in a sorted array
and then put all smaller elements (smaller than x) before x, and put all greater elements (greater than x) after x.
Given the following Pseudo Code for recursive QuickSort function:

/* low –> Starting index, high –> Ending index */
quickSort(arr[], low, high)
{
if (low < high)
{
/* pi is partitioning index, arr[p] is now at right place */
pi = partition(arr, low, high);
quickSort(arr, low, pi – 1); // Before pi
quickSort(arr, pi + 1, high); // After pi
}
}

For advanced users may want to compare to bubble sort for an extra point.

bestdaixie

评论已关闭。