Question

Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment...

Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name:

True/False: Circle one

Assignment 1

ID:

1. True / False 2. True / False 3. True / False 4. True / False 5. True / False 6. True / False 7. True / False 8. True / False 9. True / False 10. True / False

Variable and functions identifiers can only begin with alphabet and digit. Compile time array sizes can be non-constant variables.
Compile time array sizes must be known at compile time.
An array can have size of 0.

int m = 15.6; won’t compile because the types do not match.
int n = 11/5; will allocate memory for n and initialize with the value 2.
Array indices begin with the number 1.
You can define multiple functions with the same identifier.
Variables declared local to a function are still accessible after the function completes execution. structs by default have private access specification.

11. Suppose you’re tasked with fixing a function definition that does not work as intended. The function is supposed to compare two strings and set the count to the number of identical characters, two characters are identical if they are the same character and are in the same position in the cstring. This function will be case sensitive so the character ‘a’ is not the same as ‘A’. Note that cstrings are just character arrays that have ‘\0’ as their last character, for example

char name[7] = "harry"; might looks like this in memory:

Usage of this function might look like (Note that the usage is correct and should not be modified):

h

a

r

r

y

\0

   int count = 0;
   compareCstrings("tacocat", "TACOCAT", count);
   compareCstrings("Harry", "Malfoy", count);
   compareCstrings("SMC","SBCC", count);

Currently the function definition is:

// should set count to 0
// should set count to 1
// should set count to 2

void compareCstrings(const char str1[], const char str2[], int count) { &count = 0;

          int index;
          while (str1 != '\0' || str2 != '\0') {
                 if (str1 == str2)
                        &count++;

index++; }

}

Rewrite the function so that it satisfies specification. Try to keep the general form of the original code, you should not have to add or remove any lines of code, just modify the existing ones.

Page 1 of 8

Santa Monica College CS 20A: Data Structures with C++ Assignment 1 Spring 2019 Name: ID:

12. Use the code below to answer the questions that follow. Assume that all proper libraries and name spaces are included and that the code will compile without error. Within the main function, for the variable int last_sid , write in the last digit of your SMC student ID.

}

}

}

int foo(int a, int b) { //First

int c = a+b;

while(c>=3)

c-=3;

return c;

//------------------------------------

char foo(string a, int b) { //Second

return a[b];

//------------------------------------ string foo(int b, string &a) { //Third

string sub = a.substr(3*b,3);
a.replace(3*b,3,"...");

return sub;

//--------------------------------------

void main() {

int last_sid = ____; //<-Last digit of your SID

string letters("ggfiorkcboneat !!!ws adtarojot");

string output("");
int numbers[] = {0,8,3,7,4,6,9,1,2,5};
for(int i=0; i<10; i++) {

}

int j = numbers[i];
numbers[i] = foo(last_sid,i);
string s = foo(j, letters);
output += foo(s, numbers[i]);
cout << output;

}

a.) What is it called when we use the same function identifier for multiple functions? What must we do to allow the compiler to differentiate between functions with the same identifier?

Page 2 of 8

Santa Monica College CS 20A: Data Structures with C++ Assignment 1 Spring 2019 Name: ID:

b.) What does the string letters look like at the end of second iteration? The blocks below are placed for your convenience, you may overwrite the values.

ggfiorkcboneat !!!ws adtarojot

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

c.) What does the numbers array look like at the end of the program? The blocks below are placed for your convenience, you may overwrite the values.

0837469125

d.) (3 points) What is printed with cout << output << endl; ?

*Extra blocks for work if needed:

ggfiorkcboneat !!!ws adtarojot

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

ggfiorkcboneat !!!ws adtarojot

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

0837469125 0837469125

Page 3 of 8

Santa Monica College CS 20A: Data Structures with C++ Assignment 1 Spring 2019 Name: ID:

13. Implement the class Tiktok discussed below. You may assume both iostream and string libraries are included, you may not use any other libraries. There are 60 seconds in a minute, 3600 seconds in an hour, 60 minutes in an hour. The 24-hour clock convention goes from 0:0:0 to 23:59:59. Read everything before starting that way you get a better sense on what member variables you need and how you want to implement the member functions. Note that what we expect to see in the console output is not necessarily what we may want to store as member variables.

It may be useful to recall that the modulus operator “%” can be used to obtain the remainder of integer division, also the “+” operator may be used to concatenate strings, and the function std::to_string(int) takes an integer and returns the string equivalent of that integer, presumably for concatenating a string with an integer.

  • Implement the default constructor which sets the initial state of Tiktok to correspond to time 0:00:00 in 24-hour clock convention (or 12:00:00 AM 12-hour clock convention).

  • addSeconds adds the number of seconds passed into the function to Tiktok. If the amount of seconds to add is negative do nothing. There is no upper limit to the amount of seconds that can be added.

  • addMinutes adds the number of minutes passed into the function to Tiktok. If the amount of minutes to add is negative do nothing. There is no upper limit to the amount of minutes that can be added.

  • addHours adds the number of hours passed into the function to Tiktok. If the amount of hours to add is negative do nothing. There is no upper limit to the amount of hours that can be added.

  • display24 prints to the console the time stored in Tiktok using 24-hour convention; with the following format: XX:XX:XX, followed by a newline.

  • display12 prints to the console the time stored in Tiktok using 12-hour convention. It will print AM or PM appropriately; with the following format XX:XX:XX XM, followed by a newline

    Below is the class definition for Tiktok, presumably in some header file. After planning out your design declare your member variables in the private field of the class.

          class Tiktok {
          public:
    

    Tiktok();

                void addSeconds(int s);
                void addMinutes(int m);
                void addHours(int h);
    
                void display24() const;
                void display12() const;
    

    private:
    //TODO: Declare any member variables you think you will need.

    };

Page 4 of 8

Santa Monica College CS 20A: Data Structures with C++

Assignment 1

ID:

Spring 2019
Below is example usage for Tiktok :

      void main() {
            Tiktok tt;

Name:

// Declare an instance of Tiktok

// 12:0:0 AM
// 0:0:0
// 12:59:0 AM
// 0:59:0
// 1:0:0 AM
// 1:0:0
// 11:59:59 AM
// 11:59:59
// 12:0:0 PM
// 12:0:0
tt.addHours(48);
tt.display12();
tt.display24();
cout << endl;
tt.addMinutes(59);
tt.display12();
tt.display24();
cout << endl;
tt.addSeconds(60);
tt.display12();
tt.display24();
cout << endl;
tt.addHours(10);
tt.addMinutes(59);
tt.addSeconds(59);
tt.display12();
tt.display24();
cout << endl;
tt.addSeconds(1);
tt.display12();
tt.display24();
cout << endl;

tt.addSeconds(11 * 3600 + 12 * 60 + 8);

//11hr*3600s/hr + 12m*60s/m + 8s = 40328s

      tt.display12();
      tt.display24();
      cout << endl;
      tt.addMinutes(47);
      tt.display12();
      tt.display24();
      cout << endl;
      tt.addSeconds(52);
      tt.display12();
      tt.display24();
      cout << endl;

}

// 11:12:8 PM
// 23:12:8
// 11:59:8 PM
// 23:59:8
// 12:0:0 AM
// 0:0:0

Page 5 of 8

Santa Monica College CS 20A: Data Structures with C++ Assignment 1 Spring 2019 Name: ID:

Implement the member functions of Tiktok below, assume this being done in a separate source file. Be as neat and syntactically correct as possible.

a) Constructor:

b) addSeconds:

Page 6 of 8

Santa Monica College CS 20A: Data Structures with C++ Assignment 1 Spring 2019 Name: ID:

c) addMinutes:

d) addHours:

Page 7 of 8

Santa Monica College CS 20A: Data Structures with C++ Assignment 1 Spring 2019 Name: ID:

e) display24:

f) display12:

Page 8 of 8

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1. False. Identifier has a rule that it should begin with any of the alphabet or it might start with _ that is underscore.

Answer 2 . False . Array that are going to compile at compile time should have constant size, it should not be variable.

Answer 3. True . Array that are going to compile at compile time so that's size should be known before the compilation.

Answer 4. False . No you can't have array that is of 0 size.

Add a comment
Know the answer?
Add Answer to:
Santa Monica College CS 20A: Data Structures with C++ Spring 2019 Name: True/False: Circle one Assignment...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CS 20A: batar Santa Monica College Spring 2019 Namen Multiple Choice: Circle the answer that fits...

    CS 20A: batar Santa Monica College Spring 2019 Namen Multiple Choice: Circle the answer that fits best and write out your letter choice into the provided Suppose that items A, B, C, D, and E are pushed, in that order, onto an initially empty stack. Then the stack is popped four times, each time an item as popped it is ther inserted into an initially empty queue. If two itemns are then popped from the queue, space. what is the...

  • Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will...

    Data Structures and Algorithm Analysis – Cop 3530 Module 3 – Programming Assignment This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a copy constructor, (6) overload the assignment operator, (7) overload the insertion...

  • I need to update this C++ code according to these instructions. The team name should be...

    I need to update this C++ code according to these instructions. The team name should be "Scooterbacks". I appreciate any help! Here is my code: #include <iostream> #include <string> #include <fstream> using namespace std; void menu(); int loadFile(string file,string names[],int jNo[],string pos[],int scores[]); string lowestScorer(string names[],int scores[],int size); string highestScorer(string names[],int scores[],int size); void searchByName(string names[],int jNo[],string pos[],int scores[],int size); int totalPoints(int scores[],int size); void sortByName(string names[],int jNo[],string pos[],int scores[],int size); void displayToScreen(string names[],int jNo[],string pos[],int scores[],int size); void writeToFile(string...

  • (Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the...

    (Coding done in c++, Virtual Studio) Having a problem with the line trying to compare the date of birth.            **fall.sort(compare_DOB); //Here lies your error** #include <fstream> #include <iostream> #include <string> #include <list> #include <cctype> using namespace std; const char THIS_TERM[] = "fall.txt"; const string HEADER = "\nWhat do you want to do ?\n\n" "\t. Add a new friend name and DOB ? \n" "\t. Edit/Erase a friend record ? \n" "\t. Sort a Friend's record ? \n"...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • I need help with this assignment, can someone HELP ? This is the assignment: Online shopping...

    I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...

  • Objectives: The main objective of this assignment is checking students’ ability to implement membership functions. After...

    Objectives: The main objective of this assignment is checking students’ ability to implement membership functions. After completing this assignment, students will be able to:  implement member functions  convert a member function into a standalone function  convert a standalone function into a member function  call member functions  implement constructors  use structs for function overloading Problem description: In this assignment, we will revisit Assignment #1. Mary has now created a small commercial library and has managed...

  • -can you change the program that I attached to make 3 file songmain.cpp , song.cpp ,...

    -can you change the program that I attached to make 3 file songmain.cpp , song.cpp , and song.h -I attached my program and the example out put. -Must use Cstring not string -Use strcpy - use strcpy when you use Cstring: instead of this->name=name .... use strcpy ( this->name, name) - the readdata, printalltasks, printtasksindaterange, complitetasks, addtasks must be in the Taskmain.cpp - I also attached some requirements below as a picture #include <iostream> #include <iomanip> #include <cstring> #include <fstream>...

  • Name the program for this assignment "bst_driver.cpp." In this assignment you will make several modifications to...

    Name the program for this assignment "bst_driver.cpp." In this assignment you will make several modifications to the BST class in the file “bst.cpp” that I provided. Consider the following: 1. Change the declaration of treenode to class treenode //node in a BST { public: string county_name; double population_size; treenode *lchild, *rchild; //left and right children pointers }; 2. Make the following changes to the BST class: a) change the name from “BST” to “bst”; b) change default constructor from “BST”...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT