Cash-back offer from April 14th to 21st, 2024: Get a flat 10% cash-back credited to your account for a minimum transaction of $50.Post Your Questions Today!

Question DetailsNormal
$ 25.00

Homework 2 | Complete Solution | Rated A+

Question posted by
Online Tutor Profile
request

Homework 2

Name:

 

Programming

Concepts

SMU

ID:

Structures

(Ch. 22.2)

 

  1. Using the struct keyword, create structures that match The following definitions. Unless explicitly specified, you may use any data type that you see fit for the members of the structures. The first one is done for you as an example. (5 points each)

 

a. Create a Card structure that holds a playing card’s face and suit.

struct Card {

string face;

string suit;

};

 

b. Create a Student structure that holds

a first name, last name, and student id.

 

c. Create a Product structure that holds an item name and price in dollars.

 

d. Create an Employee structure that holds a full name and a boss(which is are ference to this Employee type).

 

Note that you might have to look up self--‐ referencing structures to figure this one out.

 

2. The Card structure below represents a playing card with a face value and a suit. Using the main code given, set the cards in the deck array to be one of each kind of playing card.

The order doesn’t matter. (20 points)

 

5 point bonus: set the deck using only one loop.

struct Card {

string face;

string suit;

};

//In main

Card deck[52];

int numFaces = 13;

int numSuits = 4;

string faces[numFaces] = { “Ace”, “Two”, “Three”, “Four”,

“Five”, “Six”, “Seven”, “Eight”, “Nine”, “Ten”, “Jack”,

“Queen”, “King” };

string suits[numSuits] = { “Hearts”, “Spades”, “Diamonds”,

“Clubs” };

//Fill deck here

 

Type aliases

(Ch. 22.3)

3. What does a type alias do? Does it create a new data type? How do you use an alias after you create it?

(6 points)

 

4. For each of the following examples, create one type alias using the “typedef” keyword and another using the “using” keyword. The first one is done for you as an example.

(5 points each)

 

a. The type “name” as a string.

typedef string name;

using name = string;

 

b. The type “student_id” as an unsigned integer.

 

c. The type “grade” as a pointer to a character.

 

d. Using the Card structure from the previous question in this homework, create the type “deck” as an array of 52 Cards

(Card[52]).

 

Pointer Concepts

(Ch. 8)

5. Fill in the blanks of the following statements. You may write them in the blank space under the statements. (4 points each)

 

  1. A pointer is a variable that contains as its value the _________ of another variable.
  2. The three values you can use to set the pointer to null are__________, ___________, and___________.
  3. c. If you don’t initialize a pointer to null, you should set it to ______________________________________________.
  4. The notations used to access values in a sequence in memory are the pointer/________ notation and the pointer/_________ notation.
  5.  The sizeof operator determines the size of a type, variable, or  constant measured in units of __________.
  6. A pointer--‐based string ends with a special character called the _____________.

 

 

 

Pointer Practice

(Ch. 8)

 

6. What does the following code output to the console?

Be sure to format the output exactly as it would appear. There are no errors. (20 points)

#include

using namespace std;

void mystery(int*, int*, size_t);

void printArray(int*, size_t);

int main() {

int numbers1[5] = {1, 2, 3, 4, 5};

int numbers2[5] = {1, 1, 1, 1, 1};

int numbers3[8] = { };

mystery(numbers2, numbers1, 5);

mystery(numbers3 + 3, numbers1, 5);

printArray(numbers1, 5);

printArray(numbers2, 5);

printArray(numbers3, 8);

}

void mystery(int *p1, int *p2, size_t length) {

for(int x = 0; x < length; x++) {

*(p1 + x) += *(p2 + x);

}

}

void printArray(int *p, size_t length) {

for(int x = 0; x < length; x++) {

cout << p[x] << " ";

}

cout << endl;

}

Available Answer
$ 25.00

[Solved] Homework 2 | Complete Solution | Rated A+

  • This Solution has been Purchased 1 time
  • Submitted On 01 Mar, 2015 01:56:25
Answer posted by
Online Tutor Profile
solution

Type alias is name that refer previousl...

Buy now to view the complete solution
Other Similar Questions
User Profile
Symone

Homework Assignment AA

Receive excel file too Homework Assignment AA all at 10 ...
User Profile
Symone

Homework Assignment AA

Kindly receive your completed Homework Assignment AA. There are two files namely word containing description and an excel file containing calculation of ratios...
User Profile
quizh...

Homework Assignment 3

Employee Salary Department dep1 dep2 dep3 dep4 3 $32,782 1 $32,782 $35,467 $23,654 $65,487 8 $32,920 1 $32,920 $35,468 $36,578 $46,184 9 $29,548 1 $29,548 $29,876 $37,548 $54,899 18 $39,828 1 $39,828 $43,674 $53...
User Profile
DEEPE...

Stat Homework Help

STAT 200 Week 7 Homework Problems: 10.1.2 Table #10.1.6 contains the value of the house and the amount of rental income in a year that the house brings in ("Capital and rental," 2013). Create a scatter plot and find a reg...
User Profile
Symone

Milestone 2 Assignment

Homework Assignment 2. Kindly receive your completed work. Download both word and excel file attached. Thank you. ...

The benefits of buying study notes from CourseMerits

homeworkhelptime
Assurance Of Timely Delivery
We value your patience, and to ensure you always receive your homework help within the promised time, our dedicated team of tutors begins their work as soon as the request arrives.
tutoring
Best Price In The Market
All the services that are available on our page cost only a nominal amount of money. In fact, the prices are lower than the industry standards. You can always expect value for money from us.
tutorsupport
Uninterrupted 24/7 Support
Our customer support wing remains online 24x7 to provide you seamless assistance. Also, when you post a query or a request here, you can expect an immediate response from our side.
closebutton

$ 629.35