Related questions
Concept explainers
Implement the copy constructor for the StringVar class using the options given on the right side window. Place the code into the left side using the arrows. NOTE: Be careful! There are decoys!
Assume that StringVar.h has the following declaration:
#include <iostream>
class StringVar {
public:
StringVar() : max_length(20) { // Default constructor size is 20
value = new char[max_length+1];
value[0] = '0円';
}
StringVar(int size); // Takes an int for size
StringVar(const char cstr[]); // Takes a c-string and copies it
StringVar(const StringVar& strObj); // Copy Constructor
~StringVar(); // Destructor
int size() const { return max_length; } // Access capacity
const char* c_str() const { return value; } // Access value
int length() const { return strlen(value); } // Access length
StringVar& operator= (const StringVar& rightObj);
std::istream& operator>> (std::istream& in, StringVar& strVar);
std::ostream& operator<< (std::ostream& out, const StringVar& strVar);
private:
int max_length;
char* value;
};
Organize blocks of code:
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- import java.util.ArrayList; /*** A class to hold details of audio files.** @author David J. Barnes and Michael Kölling* @version 2011年07月31日*/public class MusicOrganizer{// An ArrayList for storing the file names of music files.private ArrayList<String> files;/*** Create a MusicOrganizer*/public MusicOrganizer(){files = new ArrayList<String>();}/*** Add a file to the collection.* @param filename The file to be added.*/public void addFile(String filename){files.add(filename);}/*** Return the number of files in the collection.* @return The number of files in the collection.*/public int getNumberOfFiles(){return files.size();}/*** List a file from the collection.* @param index The index of the file to be listed.*/public void listFile(int index){if(index >= 0 && index < files.size()) {String filename = files.get(index);System.out.println(filename);}}/*** Remove a file from the collection.* @param index The index of the file to be removed.*/public void...arrow_forwardThis class contains a number of syntax and semantic errors.Your job is to find them all. public Class DebugMe{ public static void main(String args[]){ printSums(args); compareBoxes(); } //This function is designed to print the sums of all numbers between 1 and the //first number entered as an argument to DebugMe //For example, if you enter: DebugMe 3 //You should get: // The sum of the first 1 numbers is 1. // The sum of the first 2 numbers is 3. // The sum of the first 3 numbers is 6. public static void printSums(String[] args){ { int count; count = Integer.parseInt(args); for (i = 1 ; i <= count ; i++); { int sum = 0; int i = 0; sum += i - 1; System.out.println("The sum of the first " + i + " numbers is " + sum + "."); } } //This function demonstrates the use of the Box class //DO NOT change anything in this function //use it to...arrow_forwardusing java programming code the followingarrow_forward
- How do I fix the code? import java.util.*; import java.util.Arrays; public class Movie { private String movieName; private int numMinutes; private boolean isKidFriendly; private int numCastMembers; private String[] castMembers; // default constructor public Movie() { this.movieName = "Flick"; this.numMinutes = 0; this.isKidFriendly = false; this.numCastMembers = 0; this.castMembers = new String[10]; } // overloaded parameterized constructor public Movie(String movieName, int numMinutes, boolean isKidFriendly, String[] castMembers) { this.movieName = movieName; this.numMinutes = numMinutes; this.isKidFriendly = isKidFriendly; this.numCastMembers = castMembers.length; this.castMembers = new String[numCastMembers]; for (int i = 0; i < castMembers.length; i++) { this.castMembers[i] = castMembers[i]; } } // set the number of minutes public void setNumMinutes(int numMinutes) { this.numMinutes = numMinutes; } // set the movie name public void setMovieName(String movieName) { this.movieName...arrow_forwardHow do I make the code work? Code: import java.util.*; import java.util.Arrays; public class Movie { private String movieName; private int numMinutes; private boolean isKidFriendly; private int numCastMembers; private String[] castMembers; // default constructor public Movie() { this.movieName = "Flick"; this.numMinutes = 0; this.isKidFriendly = false; this.numCastMembers = 0; this.castMembers = new String[10]; } // overloaded parameterized constructor public Movie(String movieName, int numMinutes, boolean isKidFriendly, String[] castMembers) {this.movieName = movieName;this.numMinutes = numMinutes;this.isKidFriendly = isKidFriendly;this.numCastMembers=0;this.castMembers=new String[castMembers.length];for(int i=0;i<castMembers.length;++i){this.castMembers[i] = castMembers[i];if(castMembers[i]!=null)this.numCastMembers++;} }// set the number of minutes public void setNumMinutes(int numMinutes) { this.numMinutes = numMinutes; } // set the movie name public void setMovieName(String...arrow_forwardWrite a string class. To avoid conflicts with other similarly named classes, we will call our version MyString. This object is designed to make working with sequences of characters a little more convenient and less error-prone than handling raw c-strings, (although it will be implemented as a c-string behind the scenes). The MyString class will handle constructing strings, reading/printing, and accessing characters. In addition, the MyString object will have the ability to make a full deep-copy of itself when copied. Your class must have only one data member, a c-string implemented as a dynamic array. In particular, you must not use a data member to keep track of the size or length of the MyString. #include "mystring.h" #include <cctype> #include <iostream> #include <string> using namespace std; using namespace cs_mystring; void BasicTest(); void RelationTest(); void CopyTest(); MyString AppendTest(const MyString& ref, MyString val); string boolString(bool...arrow_forward
- Below is the code for a Time class that has both an equals method and a hashCode method; however, the body of the hashCode method is missing. In the text box, write the code you would put inside the body of the hashCode method. Remember that a hashCode with no collisions is better than a hashCode that has collisions and a hashCode with no gaps in the values is better than a hashCode that has gaps. public class Time { private int hour; // A number between 1 and 12 private int min; // A number between 0 and 59 private boolean pm; // True if the time is pm. public Time(int hour, int min, boolean pm) { this.hour = hour; this .min = min; this.pm = pm; } public int getHour() { return hour; } public int getMin() { return min; } public boolean isPM() { return pm == true; } public boolean isAM() { return pm == false; } public boolean equals(Object obj) { if (this == obj) return true; if (obj ==...arrow_forwardThe following is the specification for the constructor of a EmailFolder class: /*** Creates a new EmailFolder with the given label** @precondition label != null AND !label.isEmpty()* @postcondition getLabel()==label*/public EmailFolder(String label) Assume the variable folders is an array list of EmailFolder objects. Write code to add a new EmailFolder to the list.arrow_forwardI'm stuck on this question and I don't know how I should be approaching this. What should I do? My code so far: ----------------- #include <iostream> using namespace std; class Student{ public: Student():grade(0.0){} void setGrade(double value){ grade = value; } void setName(string value){ name = value; } void setMajor(string value){ major = value; } double getGrade(){ return grade; } string getName(){ return name; } string getMajor(){ return major; } void addStudent(double grade, string value1, string value2){ Student::setGrade(grade); Student::setName(value1); Student::setMajor(value2); } void display(){ cout<<"Name: "<<Student::getName()<<endl; cout<<"Major: "<<Student::getMajor()<<endl; cout<<"GPA: "<<Student::getGrade()<<endl; cout<<"Grade: "; } private: class GPA{ public: GPA(){} void getLetterGrade(double grade) const{ if (grade >= 3.5){ cout<<"A"; } if (grade >= 2.5...arrow_forward
- Write an application that displays the strings in the provided array alphabetically in ascending order. import java.util.*; public class StringSort { publicstaticvoidmain(String[] args) { String[] values = {"mouse","dog","cat","horse","cow", "moose","tiger","lion","elephant","bird","hamster", "guinea pig","leopard","aardvark","hummingbird"}; }arrow_forwardModify the code so that it reads a file named city.txt into starray, then do the linear search CODE class LinSearchclass{ public static int findit( String[] starray, String lookforthis ) { for ( int j=0; j < starray.length; j++ ) if ( starray[j] != null ) if ( starray[j].equals( lookforthis) ) return j ; return -1 ; }} //public class Linsearch { public static void main(String[] args) { final int theSize = 10 ; String[] strarr = new String[ theSize ] ; strarr[0] = "Brooklyn" ; strarr[1] = "Queens" ; strarr[2] = "Phila" ; strarr[3] = "LA" ; strarr[4] = "Manhattan" ; strarr[6] = "Cincinnati" ; strarr[7] = "Pittsburgh" ; strarr[8] = "Albany" ; // show cells with data for (int j=0; j < strarr.length; j++ ) if ( strarr[j] != null ) System.out.println( j + ": " + strarr[j] ); // search for "Manhattan" int location = LinSearchclass.findit( strarr, "Manhattan" ); if ( location...arrow_forwardI ran this code but it was correct half way; public class DebugEight2 { publicstaticvoidmain(Stringargs[]) { int[] someNums = {4,17,22,8,35}; int tot =0, avg =0; int x; for(x =0; x < someNums.length; ++x) tot += someNums[x]; avg = tot / someNums.length; System.out.println("Sum is " + tot); System.out.println("Average is " + avg); } } Please see attached screenshot of the program and output and alsoarrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education