(please use zelle's Python Graphics
library, I've
already asked this question and have had to post
this multiple times. I am working with the Python Graphics library
and nothing else. thank you! note that I will downvote anything
other than python graphics. this is the 4th time I've had to post
this same question)
im trying to create a function that has a circle
bouncing left to right on a window and when the
circle is clicked on, it stops moving horizontally
and begins moving up and down on the window.
In: Computer Science
Using the following code write the following instructions in C++
Implementation:
1. Re-implement your String class to use a dynamically allocated array for storage. It will be a NULL terminating charater array.
2. This dynamic version of the String will only allocate exactly the amount of memory necessary to store the characters. That is, the length will be the same as the capacity. However, the size of the dynamic array needs to have an extra char for the NULL terminator.
3. To re-write the constructors to allocate the correct amount of memory.
4. The default constructor allocates an array of size 1 for the empty string. The other constructors will allocate memory as needed. For example for String str("abc"); str.capacity() == 3, str.length() == 3, and str.string_size == 4.
5. Implement a destructor, copy constructor, constant time swap, and assignment operator for your ADT.
6. You will need to re-implement capacity(). length() remains the same.
7. You will also have to update concat and += to return the proper sized string result.
8. Implement the private constructors String(int) and
String(int, const char *).
String(int) constructs the object as the emptry string with int
capacity.
String(int, const char *) works the same as String(const char *)
but allocates int capacity.
9. Implement a private method reset_capacity to change the capacity of your string while keeping the contents intact. That is, create a new array and copy contents over to the new array, making sure to clean up memory.
10. The private constructors and method may be useful for re-implementing + and +=.
Testing:
11. Write tests for the methods developed for this project.
12. Write test cases first. Testing must be thorough. You will be relying on the String to be correct.
13. You should make sure that the test cases you develop are very complete.
14. The otests test the constructors, assignment, copy, +, ==, and <.
15. If you add additional member variables the tests will not work properly.
--------------------------------------------------------------------------------
string.hpp
--------------------------------------------------------------------------------
#ifndef STRING_HPP #define STRING_HPP #include <iostream> /** * @invariant str[length()] == 0 * && length() == capacity() * && capacity() == stringSize - 1 */ class String { private: // helper constructors and methods String(int); String(int, const char *); void reset_capacity (int); char * str; // size includes NULL terminator int string_size; public: // constructor: empty string, String('x'), and String("abcd") String(); String(char); String(const char *); // copy ctor, destructor, constant time swap, and assignment String(const String &); ~String(); void swap (String &); String & operator= (String); // subscript: accessor/modifier and accessor char & operator[](int); char operator[](int) const; // max chars that can be stored (not including null terminator) int capacity() const; // number of char in string int length () const; // concatenation String operator+ (const String &) const; String & operator+=(String); // relational methods bool operator==(const String &) const; bool operator< (const String &) const; // i/o friend std::ostream& operator<<(std::ostream &, const String &); friend std::istream& operator>>(std::istream &, String &); }; // free functios for concatenation and relational String operator+ (const char *, const String &); String operator+ (char, const String &); bool operator== (const char *, const String &); bool operator== (char, const String &); bool operator< (const char *, const String &); bool operator< (char, const String &); bool operator<= (const String &, const String &); bool operator!= (const String &, const String &); bool operator>= (const String &, const String &); bool operator> (const String &, const String &); #endif
---------------------------------------------------------------------------------------------------------------------------
string.cpp
---------------------------------------------------------------------------------------------------------------------------
#include <iostream> #include <cassert> #include "string.hpp" String::String(){ str[0] = 0; } String::String(char ch){ str[0] = ch; str[1] = 0; } String::String(const char* s){ int pos = 0; while(s[pos] != 0){ str[pos] = s[pos]; ++pos; if(pos >= capacity()) break; } str[pos] = 0; } int String::length() const{ int size = 0; while(str[size] != 0) ++size; return size; } int String::capacity() const{ return STRING_SIZE -1; } char& String::operator[](int i){ assert(i >= 0); assert(i <= length()); return str[i]; } void String::swap(String& str1){ int tempStr = string_size; string_size = str1.string_size; str1.string_size = tempStr; int* tempStr1 = str; str = str1.str; str1.str = tempStr1; } char String::operator[](int i) const{ assert(i >= 0); assert(i <= length()); return str[i]; } bool String::operator==(const String& rhs) const{ int pos = 0; while(str[pos] != 0 && str[pos] == rhs.str[pos]){ ++pos; } return str[pos] == rhs.str[pos]; } std::istream& operator>>(std::istream& in, String& rhs){ in >> rhs.str; return in; } std::ostream& operator<<(std::ostream& out, const String& rhs){ out << rhs.str; return out; } bool String::operator<(const String& rhs) const{ int pos = 0; while(str[pos] != 0 && rhs.str[pos] != 0 && str[pos] == rhs.str[pos]){ ++pos; } return str[pos] < rhs.str[pos]; } String String::operator+(const String& rhs) const{ String result(str); int offset = length(); int pos = 0; while(rhs.str[pos] != 0){ result.str[offset + pos] = rhs.str[pos]; ++pos; } result.str[offset + pos] = 0; return result; } String& String::operator+=(String rhs){ int offset = length(); int pos = 0; while(rhs.str[pos] != 0){ if((offset + pos) >= capacity()) break; str[offset + pos] = rhs.str[pos]; ++pos; } str[offset + pos] = 0; return *this; } String operator+(const char charArray[], const String& rhs){ return rhs + charArray; } String operator+(char s, const String& rhs){ return s + rhs; } bool operator==(const char charArray[], const String& rhs){ if(charArray == rhs){ return true; } else{ return false; } } bool operator==(char s, const String& rhs){ if(s == rhs){ return true; } else{ return false; } } bool operator<(const char charArray[], const String& rhs){ if(charArray < rhs){ return true; } else{ return false; } } bool operator<(char s, const String& rhs){ if(s < rhs){ return true; } else{ return false; } } bool operator<=(const String& lhs, const String& rhs){ if(lhs < rhs || lhs == rhs){ return true; } else{ return false; } } bool operator!=(const String& lhs, const String& rhs){ if(lhs.length() != rhs.length()){ return true; } int pos = 0; while(lhs[pos] != rhs[pos]){ pos++; } if(pos == lhs.length()){ return true; } return false; } bool operator>=(const String& lhs, const String& rhs){ if(lhs > rhs || lhs == rhs) { return true; } else{ return false; } } bool operator>(const String& lhs, const String& rhs){ if(!(lhs <= rhs)){ return true; } else{ return false; } }
In: Computer Science
******You do not need to get everything working exactly as it says, I mostly just need an outline of how to create this GUI and add up the costs and print them all out. Any help at all will be greatly appreciated*******
********MUST BE IN JAVAFX**********
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (via JavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information:
Pricing (assign these prices to each item)
Base Price for items :
Additional fees for Toppings:
Conditions:
In: Computer Science
Discussion about strategies to identify critical satiations in informatics systems
In: Computer Science
c program
Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
In: Computer Science
Given an array A of n integers, describe an O(n log n)
algorithm to decide if the elements of A are all distinct. Why does
your algorithm run in O(n log n) time?
In: Computer Science
using the C programming language I need a program that includes comments/ screen shots that it works/ and the code it self
for a hang man game
this game has to be to complie no errors please you can even keep it super basic if u want and no( studio.c) that never works THANK UUUUUU
In: Computer Science
27. Which of the following chart types can be created as a PivotChart? Select all the options that apply.
|
||||||||||||
28. You should not move a PivotChart because it must be on the same worksheet as its PivotTable.
|
||||||||||||
29. Which of the following formatting options can you apply to PivotCharts and other Excel charts? Select all the options that apply.
|
In: Computer Science
Show how each of the following C statements would be
translated to ARM Cortex M3/M4
assembly language:
3.1. a |= (1<<3)
3.2. a &= ~(1<<1)
3.3. a ^= 1<<2
If a was an 8-bit variable with initial value 0xA7:
3.4. What would be its value after each operation, assuming each
operation runs individually.
In: Computer Science
Define and test a function myRange. This function should behave like Python’s standard range function, with the required and optional arguments, but it should return a list. Do not use the range function in your implementation!
Study Python’s help on the range to determine the names, positions, and what to do with your function’s parameters. Use a default value of None for the two optional parameters. If these parameters both equal None, then the only provided argument should be considered the stop value, and the start value should default to 0. If just the third parameter equals None, then the function has been called with a start and stop value. Thus, the first part of the function’s code establishes what the values of the parameters are or should be. The rest of the code uses those values to build a list by counting up or down.
An example of the range function with only one argument provided is shown below:
print(myRange(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In: Computer Science
IN BASIC PYTHON:
Cafeteria Selections Program. This program permits students to choose their lunch purchases from a menu in the cafeteria. It calculates the tax on taxable items (candy, pop) and presents the user with a total. The program accepts a tendered amount and computes and outputs change down to the actual coins and bills involved. An added inventory component could keep a running total of individual items purchased. No graphics needed here.
Mars Bar $1.25
Kit Kat $1.25
Soda Pop $1.50
Water $1.00
Muffins $2,00
Coffee / Tea $1.75
Expresso / Specialty Teas $2.50
Cold Sandwiches $5.00
Pasta $7.50
Gum $.140
In: Computer Science
C# Programming
In C# .NET you can build 3 different kinds of Presentation Layers. List them.
In: Computer Science
(3) Briefly (in just a few words), describe the difference between
an instance and a class.
In: Computer Science
Define a function replaceCharAtPos(orig,pos) which receives two input parameters, a string (orig) and a positive integer number (pos).
If the number is a position within the string, the function should
return a new string. The new string should be the original
string except that instead of the original character in that
position pos, it should have the position number itself (if the
position number has more than 1 digit, the character should be
replaced by the digit in the units part of the position number,
e.g. 2 if the position number is 12).
If the number pos is not a valid position within the original
string orig, the string returned should be exactly the same as the
original string.
For example
replaceCharAtPos('abcd',1) should return 'a1cd'
replaceCharAtPos('abcd',10) should return 'abcd'
replaceCharAtPos('abcdefghijklmn',12) should return
'abcdefghijkl2n'
As an example, the following code fragment:
print (replaceCharAtPos("abcd",2))
should produce the output:
ab2d
language: Python
In: Computer Science
(a) Why can't records use private data members (instead of public).
(b) Why shouldn't objects use public data members?
In: Computer Science