Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The app we were taught using is visual studios 2015 with the format following: #

ID: 3856714 • Letter: T

Question

The app we were taught using is visual studios 2015

with the format following:

#include <iostream>

using namespace std;

int main()

{

system("pause");

return 0;

}

Objective Exercise creating, accessing and printing from dynamically allocated array. Task Given array in main) int array[ 1,2,3,4,5,6,7,8,9, 10); Write a code that fulfills the following requirements: . Declare the given array[ in main . Place the following functions below main). o int array[ ]=(1,2,3,4,5,6,7,8,9,10); Create a pointer & dynamically create array for this pointer in createArray) function. Copy this array into allocated memory in copyArray() function -pass parameters appropriately Create a function, freeMemory(),to free up memory make sure to pass the array correctly Now, print dynamically created array but make sure to parse through using pointer notation in printArray() function reference the value contained in a Now, call these above created functions in given order. o (px+ o createArray() o copyArray) o printArray() o freeMemory)

Explanation / Answer

VISUAL Studio


string myName;
static void Main(string[ ] args).
{
string myName;
Console.WriteLine("Please enter your name");
myName = Console.ReadLine( );
Console.WriteLine("Hello {0}", myName);
}

static void Main(string[] args)
{
try
{
int valueOne;
int valueTwo;
int valueThree;
System.Console.WriteLine
("Please Enter A Whole Number: ");
valueOne = int.Parse(Console.ReadLine());
System.Console.WriteLine
("Please Enter Another Whole Number: ");
valueTwo = int.Parse(Console.ReadLine());
valueThree = valueOne + valueTwo;
if (valueThree > 0)
{
System.Console.WriteLine
("The Sum of ValueOne: {0} and ValueTwo: {1} is Equal
to: {2}", valueOne, valueTwo, valueThree);
}
else
{
System.Console.WriteLine
("Both Values were Zero!");
}
}

catch (System.FormatException)
{
Console.WriteLine(
"You didn't enter a Whole Number!");
}
Console.WriteLine(
'n' + "Please Press any Key to Exit");
System.Console.ReadKey();
}
int intMax = intFirst;
if (intSecond > intMax) intMax = intSecond;
if (intThird > intMax) intMax = intThird;
Console.WriteLine("The largest is {0}", intMax);

string myCountry;
System.Console.WriteLine
("Please Enter A Country: ");
myCountry = Console.ReadLine();

switch (myCountry)
{
case "England":
Console.WriteLine("Your Capital is London.n");
break;
case "France":
Console.WriteLine("Your Capital is Paris.n");
break;
case "Germany":
Console.WriteLine("Your Capital is Munich.n");
break;
default:
Console.WriteLine("The Capital is Unknown.n");
break;
}
int counter = 1;
int counterb = 0;

for (; counter < 101; counter++)
{

counterb++;
if (counterb == 10)
{
Console.WriteLine(
"counter: {0} ", counter);
counterb = 0;
}
}
int counterVariable = 0;
int nextCounter = 0;

string numberRow = " ";

for (counterVariable = 1; counterVariable < 101; counterVariable++)
{

nextCounter++;
if (counterVariable < 11)
{
numberRow += Convert.ToString(counterVariable) + " ";
}
else
{
numberRow += Convert.ToString(counterVariable) + " ";
}

if (nextCounter == 10)
{
Console.WriteLine(numberRow);
numberRow = " ";
nextCounter = 0;
}
}

int valueOne;
int valueTwo;

const int multiplyer = 12;
Console.WriteLine(
"Please enter a number between 1 and 12");
valueOne = int.Parse(Console.ReadLine());

if (valueOne > 0 && valueOne < 13)
{
valueTwo = valueOne * multiplyer;
Console.WriteLine(
valueOne + " x " + multiplyer + " = " + valueTwo);
}
else
{
Console.WriteLine(
"You didn't enter a number between 1 and 12");
}
valueThree = valueOne * valueTwo;

if (valueOne > 0 && valueTwo > 0)
{
Console.WriteLine(
"The answer is a Positive Number. The answer is: "
+ valueThree);

} else if (valueOne < 0 && valueTwo < 0)
{
Console.WriteLine(
"The answer is a Positive Number. The answer is: " + valueThree);
}

else if (valueOne < 0 || valueTwo < 0)
{
Console.WriteLine(
"The answer is a Negative Number. The answer is: " + valueThree);
}
else
{
Console.WriteLine(
"Both numbers are not greater or less than 0");
}
public struct Colour
{
public int red { get; set; }
public int green { get; set; }
public int blue { get; set; }

public Colour(int rVal, int gVal, int bVal) : this()
{
red = rVal;
green = gVal;
blue = bVal;
}

public override string ToString()
{
return (String.Format("{0}, {1}, {2}", red, green, blue));
}
}

public void myFunc(Colour col)
{

col.red = 200;
col.green = 100;
col.blue = 50;
Console.WriteLine("colour1 colour: {0}", col);
}
void Order(int orderNum);
string name { get; set; }
string address { get; set; }
public class Customer : IClient
{
public Customer(string s)
{
Console.WriteLine("Creating a New Customer ID: {0}", s);
}

public void Order(int newOrder)
{
Console.WriteLine("Implementing the Order Method for IClient.
The Order Number is: {0}", newOrder);
}

public string name { get; set; }
public string address { get; set; }
}
Customer cust = new Customer("H56388");
cust.name = "Brian Ferry";
cust.address = "23 Orange Lane, Clifton, Bristol, BS6 5FH";
Console.WriteLine("The Name of the Customer is: {0}", cust.name);
Console.WriteLine("The Address of the Customer is: {0}", cust.address);
cust.Order(1234);
int[][] intArray;
intArray = new int[10][];
for (int j = 0; j < intArray.Length; j++)
{
for (int k = 0; k < intArray.Length; k++)
{
  
intValue++;
intArray[j][k] = intValue;
if (intValue < 10)
{

numberRow += Convert.ToString(intArray[j][k]) + " ";
}
else
{
numberRow += Convert.ToString(intArray[j][k]) + " ";
}
}

Console.WriteLine(numberRow);
NumberRow = " ";
}
ArrayList intArray = new ArrayList();

for (int i = 0;i<5;i++)
{
intArray.Add(i*10);
}

foreach (int i in intArray)
{
Console.Write("{0} ", i.ToString());
}
View code file.
Queue intQueue = new Queue();

for (int i = 0;i<5;i++)
{
intQueue.Enqueue(i);
}
string s1 = "http://www.bbc.co.uk";
string s2;
string s3;
int index;

s2 = s1.Substring( 0, 4);
Console.WriteLine(s2);

index = s1.LastIndexOf("/");
s2 = s1.Substring(index + 1, 3);
Console.WriteLine(s2);

index = s1.IndexOf(".");
s2 = s1.Substring(index+1);
s3 = s2.Substring(0, 3);
Console.WriteLine(s3);
string s1 = "http://www.bbc.co.uk";
// Constants for the space and comma characters
const char Space = '/';
const char Stop = '.';
const char Colon = ':';

char[] delimiters = new char[]
{
Space,
Stop,
Colon
};
string output = "";
int ctr = 1;

String[] resultArray = s1.Split(delimiters);
foreach (String subString in resultArray)
{
if (subString != "")
{
output += ctr++;
output += ": ";
output += subString;
output += "n";
}
}
Console.WriteLine(output);
public double DoDivide(double a, double b)
{
if (b == 0)
throw new System.DivideByZeroException();
if (a == 0)
throw new System.ArithmeticException();
return a / b;
}
catch (System.DivideByZeroException e)
{
Console.WriteLine(
"nDivideByZeroException! Msg: {0}",
e.Message);
}
catch (System.ArithmeticException e)
{
Console.WriteLine(
"nArithmeticException! Msg: {0}",
e.Message);
}

catch
{
Console.WriteLine(
"Unknown exception caught");
}
finally
{
Console.WriteLine("Close file here.");
}
public class Pair
{

private object[] thePair = new object[2];

public delegate comparison
WhichIsFirst(object obj1, object obj2);


public Pair(
object firstObject,
object secondObject)
{
thePair[0] = firstObject;
thePair[1] = secondObject;
}

public void Sort(
WhichIsFirst theDelegatedFunc)
{
if (theDelegatedFunc(thePair[0], thePair[1])
== comparison.theSecondComesFirst)
{
object temp = thePair[0];
thePair[0] = thePair[1];
thePair[1] = temp;
}
}

public void ReverseSort(
WhichIsFirst theDelegatedFunc)
{
if (theDelegatedFunc(thePair[0], thePair[1]) ==
comparison.theFirstComesFirst)
{
object temp = thePair[0];
thePair[0] = thePair[1];
thePair[1] = temp;
}
}
}
Pair.WhichIsFirst theDogDelegate =
new Pair.WhichIsFirst(
Dog.WhichDogComesFirst);
dogPair.Sort(theDogDelegate);
dogPair.ReverseSort(theDogDelegate);
public static comparison WhichDogComesFirst(
Object o1, Object o2)
{
Dog d1 = (Dog)o1;
Dog d2 = (Dog)o2;
return d1.weight > d2.weight ?
comparison.theSecondComesFirst :
comparison.theFirstComesFirst;
}
public class Generics<T> // Generic class
{
public void Swap<K>(ref K lhs, ref K rhs)
{
  
K temp;
temp = lhs;
lhs = rhs;
rhs = temp;
}
}

Code to create button array

private void AddButtons()

{

int xPos = 0;

int yPos = 0;

  

System.Windows.Forms.Button[] btnArray = new System.Windows.Forms.Button[26];

  

for (int i = 0; i < 26; i++)

{

  

btnArray[i] = new System.Windows.Forms.Button();

}

int n = 0;

while(n < 26)

{

btnArray[n].Tag = n + 1;

btnArray[n].Width = 24;

btnArray[n].Height = 20;

if(n == 13)

{

xPos = 0;

yPos = 20;

}

// Location of button:

btnArray[n].Left = xPos;

btnArray[n].Top = yPos;

// Add buttons to a Panel:

pnlButtons.Controls.Add(btnArray[n]);

xPos = xPos + btnArray[n].Width;

// Write English Character:

btnArray[n].Text = ((char)(n + 65)).ToString();

btnArray[n].Click += new System.EventHandler(ClickButton);

n++;

}

btnAddButton.Enabled = false; // not need now to this button now

label1.Visible = true;

}

public void ClickButton(Object sender, System.EventArgs e)

{

Button btn = (Button) sender;

MessageBox.Show("You clicked character [" + btn.Text + "]");

}

Hide Shrink Copy Code

Private Sub AddButtons()

Dim xPos As Integer = 0

Dim yPos As Integer = 0

Dim n As Integer = 0

' Declare and Initialize one variable

Dim btnArray(26) As System.Windows.Forms.Button

For i As Integer = 0 To 25

btnArray(i) = New System.Windows.Forms.Button

Next i

While (n < 26)

With (btnArray(n))

.Tag = n + 1 ' Tag of button

.Width = 24 ' Width of button

.Height = 20 ' Height of button

If (n = 13) Then ' Location of second line of buttons:

xPos = 0

yPos = 20

End If ' Location of button: .Left = xPos

.Top = yPos

' Add buttons to a Panel:

pnlButtons.Controls.Add(btnArray(n)) ' Let panel hold the Buttons

xPos = xPos + .Width ' Left of next button

' Write English Character: .Text = Chr(n + 65)

' ****************************************************************

' You can use following code instead previous line

' Dim Alphabet() As Char = {"A", "B", "C", "D", "E", "F", "G", _

' "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", _

' "U", "V", "W", "X", "Y", "Z"}

' .Text = Alphabet(n)

' ****************************************************************

' for Event of click Button

AddHandler .Click, AddressOf Me.ClickButton

n += 1

End With

End While

btnAddButton.Enabled = False ' not need now to this button now

label1.Visible = True

End Sub

' Result of (Click Button) event, get the text of button

Public Sub ClickButton(ByVal sender As Object, ByVal e As System.EventArgs) _

ndles MyBase.Click

Dim btn As Button = sender

MessageBox.Show("You clicked character [" + btn.Text + "]")

End Sub

SNIPPETS

{

"key": "cmd+k 1",

"command": "editor.action.insertSnippet",

"when": "editorTextFocus",

"args": {

"snippet": "console.log($1)$0"

}

}

Visual Studio

static void Main(string[ ] args).

{

string myName;

Console.WriteLine("Please enter your name");

myName = Console.ReadLine( );

Console.WriteLine("Hello {0}", myName);

}

================================================================================

Arrays usual basics

'Declare a single-dimension array of 5 values
Dim numbers(4) As Integer   

'Declare a single-dimension array and set array element values
Dim numbers = New Integer() {1, 2, 4, 8}

'Redefine the size of an existing array retaining the current values
ReDim Preserve numbers(15)

'Redefine the size of an existing array, resetting the values
ReDim numbers(15)

'Declare a multi-dimensional array
Dim matrix(5, 5) As Double

'Declare a multi-dimensional array and set array element values
Dim matrix = New Integer(4, 4) {{1, 2}, {3, 4}, {5, 6}, {7, 8}}

'Declare a jagged array
Dim sales()() As Double = New Double(11)() {}

Dim kindergarten As Integer = students(0)
Dim firstGrade As Integer = students(1)
Dim sixthGrade As Integer = students(6)
MsgBox("Students in kindergarten = " & CStr(kindergarten))
MsgBox("Students in first grade = " & CStr(firstGrade))
MsgBox("Students in sixth grade = " & CStr(sixthGrade))

Dim cargoWeights(10) As Double
Dim atmospherePressures(2, 2, 4, 10) As Short
Dim inquiriesByYearMonthDay(20)()() As Byte

cargoWeights = New Double(10) {}
atmospherePressures = New Short(2, 2, 4, 10) {}
inquiriesByYearMonthDay = New Byte(20)()() {}

' Assign a new array size and retain the current element values.
ReDim Preserve cargoWeights(20)
' Assign a new array size and retain only the first five element values.
ReDim Preserve cargoWeights(4)
' Assign a new array size and discard all current element values.
ReDim cargoWeights(15)

Dim i = 4
Dim j = 2

Dim numbers(10) As Integer
Dim matrix(5, 5) As Double

numbers(i + 1) = 0
matrix(3, j * 2) = j

Dim v = 2
Dim i = 1
Dim j = 1
Dim k = 1
Dim wTotal As Double = 0.0
Dim sortedValues(5), rawValues(5), estimates(2, 2, 2) As Double
Dim lowestValue = sortedValues(0)
wTotal += (rawValues(v) ^ 2)

Dim firstGuess = estimates(i, j, k)
Dim numbers = New Integer() {1, 2, 4, 8}
Dim doubles = {1.5, 2, 9.9, 18}

Dim numbers = {10, 20, 30}

For index = 0 To numbers.GetUpperBound(0)
Debug.WriteLine(numbers(index))
Next

Dim numbers = {{1, 2}, {3, 4}, {5, 6}}

For index0 = 0 To numbers.GetUpperBound(0)
For index1 = 0 To numbers.GetUpperBound(1)
Debug.Write(numbers(index0, index1).ToString & " ")
Next
Debug.WriteLine("")
Next

Public Sub Process()
Dim numbers As Integer() = GetNumbers()
ShowNumbers(numbers)
End Sub

Private Function GetNumbers() As Integer()
Dim numbers As Integer() = {10, 20, 30}
Return numbers
End Function

Private Sub ShowNumbers(numbers As Integer())
For index = 0 To numbers.GetUpperBound(0)
Debug.WriteLine(numbers(index) & " ")
Next
End Sub

Public Sub ProcessMultidim()
Dim numbers As Integer(,) = GetNumbersMultidim()
ShowNumbersMultidim(numbers)
End Sub

Private Function GetNumbersMultidim() As Integer(,)
Dim numbers As Integer(,) = {{1, 2}, {3, 4}, {5, 6}}
Return numbers
End Function

Private Sub ShowNumbersMultidim(numbers As Integer(,))
For index0 = 0 To numbers.GetUpperBound(0)
For index1 = 0 To numbers.GetUpperBound(1)
Debug.Write(numbers(index0, index1).ToString & " ")
Next
Debug.WriteLine("")
Next
End Sub

Dim sales()() As Double = New Double(11)() {}

' Set each element of the sales array to a Double
' array of the appropriate size.
For month As Integer = 0 To 11
Dim days As Integer =
DateTime.DaysInMonth(Year(Now), month + 1)
sales(month) = New Double(days - 1) {}
Next month

' Store values in each element.
For month As Integer = 0 To 11
Dim upper = sales(month).GetUpperBound(0)
For day = 0 To upper
sales(month)(day) = (month * 100) + day
Next

Dim thisTwoDimArray(,) As Integer = New Integer(9, 9) {}
MsgBox("Type of thisTwoDimArray is " & TypeName(thisTwoDimArray))
MsgBox("Type of thisTwoDimArray(0, 0) is " & TypeName(thisTwoDimArray(0, 0)))

Dim numbers = {{1, 2}, {3, 4}, {5, 6}}

For index0 = 0 To numbers.GetUpperBound(0)
For index1 = 0 To numbers.GetUpperBound(1)
Debug.Write(numbers(index0, index1).ToString & " ")
Next
Debug.WriteLine("")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote