C++ How To Program Sve & Mpl W/pe Etx A/c
1st Edition
ISBN: 9780134612386
Author: Deitel
Publisher: Pearson Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 14, Problem 14.10E
Write a series of statements that accomplish each of the following. Assume that we've defined class Person that contains the private data members
char lastName[15];
char firstName [10]:
int age;
int id;
and public member functions
// accessor functions for id
void set Id(int);
int getId() const;
// accessor functions for lastName
void setLastName (const string&);
string getLastName() const;
// accessor functions for firstName
void setFirstName(const string&);
string getFirstName() const;
// accessor functions for age
void setAge (int);
int getAge() const;
Also assume that any random-access files have been opened properly.
- Initialize nameage.dat with 100 records that store values lastName =”unassigned”, firstName = “” and age = 0.
- Input 10 last names, first names and ages, and write them to the file,
- Update a record that already contains information. If the record does not contain information, inform the user "No info".
- Delete a record that contains information by reinitializing that particular record.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Write a program that does the following:
1-Define two classes Teacher and Department. Each Teacher has a department object as follow: [3 points]
class Department{
int dno;
char *name;
//add data member to count number of departments automatically
public:
//add required methods here
//define print function that prints all details of department. Note that print function is NOT function member of class Department
};
class Teacher{
const int SSN;
char *name;
Department d;
public:
//add all required methods
//define print function that prints all details of Teacher. Note that print function is NOT function member of class Teacher
}
2-inside main do the following:
a) create array of 5 Teachers. add all required details for each object inside a loop.(do NOT use cin>>)
b)use print function for department and use print function for student.
c)define and use a function FindTeachers that takes the array of Teachers and name of department. Then the function returns a list of all Teachers…
NEED A PROGRAM CODE IN C++ IN VISUAL SRUDIO WITH OUTPUT
Write a program to overload the * operator for multiplying a Distance class object with a floating point number.
The Distance class should have meters and kilometres as data members. Add all appropriate member functions for the program to work properly. In addition, write the main function to test your class as follows:
int main()
{
Distance dist(700, 2);
dist= dist * 2;
dist = 2 * dist;
dist.display();
return 0;
}
Write a program in java a class Box having three private data members (width, depth, height)
The class has three constructors which are
having no parameter – for setting values to zero or null.
having three parameters for assigning values to height, width, depth respectively.
Overload the above constructor and use this keyword to set the values of width, height & depth.
Provide getters/setters for data members.
Write a function calculateVolume() which calculates the volume of the box.
Write test Application that demonstrates the Box class by calling all the three constructors and method, creating a Create Box object, and then displaying the Box’s width , height, length and volume
Chapter 14 Solutions
C++ How To Program Sve & Mpl W/pe Etx A/c
Ch. 14 - (Fill in the Blanks) Fill in the blanks in each of...Ch. 14 - (File Matching) Exercise 14.3 asked you to write a...Ch. 14 - (File Matching Test Data) After writing the...Ch. 14 - Prob. 14.8ECh. 14 - (File-Matching Enhancement) Its common to have...Ch. 14 - Write a series of statements that accomplish each...Ch. 14 - Prob. 14.11ECh. 14 - (Telephone-Number Word Generator) Standard...Ch. 14 - (sizeof Operator) Write a program that uses the...Ch. 14 - Prob. 14.14MAD
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In this assignment, the class declaration should come first, followed by the definitions of the class member functions, followed by the client program. #include <iostream> using namespace std; class Fraction { private: int numerator; int denominator; public: void set(int n,int d){ numerator=n; denominator=d; } int getNumerator(){ return numerator; } int getDenominator(){ return denominator; } Fraction addedTo(Fraction& r){ int a=this->numerator; int b=this->denominator; int c=r.numerator; int d=r.denominator; int e,f; e=(a*d+b*c); f=b*d; Fraction f1; f1.set(e,f); return f1; } Fraction subtract(Fraction& r){ int a=this->numerator; int b=this->denominator; int c=r.numerator; int d=r.denominator; int e,f; e=(a*d-b*c); f=b*d; Fraction f1; f1.set(e,f); return f1; } Fraction multipliedBy(Fraction& r){ int a=this->numerator; int b=this->denominator; int c=r.numerator;…arrow_forwardWrite an OOP program in C++, which contains three, classes i.e. Parent Class, Child1 Class & Child2 Class. Parent Class inherited within Child1 Class & Child2 Class. Parent Class has one member function that is Public: void Show( );. Child1 & Child2 Class will follow the signature of the Parent Class member function; each class will have different function definitions. And during running time a message will be displayed that which class object you want to create to call their member function as shown in the output below. For Example: if enter 1 then it will call parent class function If enter 2 then it will call child1 class function If enter 3 then it will call child2 class function. Hint: Solve this Program using Run Time Polymorphism.arrow_forwarddo part 4 import java.util.*; // Car classclass Car{ private String name; // Variable to hold car name private String model; // Variable to hold car model // Default constructor Car(){ this.name = null; this.model = null; } // Parametrised constructor Car(String name, String model){ this.name = name; this.model = model; } // Function to get car name public String getName(){ return this.name; }} // Dealer classclass Dealer{ private Car[] arr; // Array holding car objects for a dealer private int count; // Variable to hold number of cars under a dealer // Default constructor Dealer(){ arr = new Car[50]; count=0; } // Function to add a car under a dealer public void addCar(Car obj){ this.arr[this.count] = obj; this.count++; } // Function to check if a car exists under a dealer or not public boolean contains(String name){…arrow_forward
- This is an object oriented programming question The code should be in C++ language Create a class Student having a private data members S_ID, S_Name and S_CGPA. Now create a public member functions void getID(), void getName() and getCGPA() and finally to display all the data members, create a function void display(). In the main(), create an array of student class, size of the array should be taken from user at run time and call all the functions defined in the class. Sample Output: Student 1 Enter ID: 1 Enter Name: Ali Enter CGPA: 2.5 Student 2 Enter ID: 2 Enter Name: Ahmed Enter CGPA: 2.9 Student 3 Enter ID: 3 Enter Name: Zain Enter CGPA: 3.4 Student 1 informationID: 1 Name: Ali CGPA: 2.5 Student 2 information ID: 2 Name: Ahmed CGPA: 2.9 Student 3 information ID: 3 Name: Zain CGPA: 3.4arrow_forwardIn C++ , Write a program that creates an EvenNumber object for value 16 and invokes the getNext() and getPrevious() functions to obtain and displays these numbers. The program must contain the following, **please also implement the class A data field value of the int type that represents the integer value stored in the object. A no-arg constructor that creates an EvenNumber object for the value 0. A constructor that constructs an EvenNumber object with the specified value. A function named getValue() to return an int value for this object. A function named getNext() to return an EvenNumber object that represents the next even number after the current even number in this object. A function named getPrevious() to return an EvenNumber object that represents the previous even number before the current even number in this object.arrow_forwardThe two header files below describe the interface of the base class Person and its derived class Empolyee, respectively. Please implement all the functions declared in these two header files in their corresponding .cpp files. 1. Header file: Person.h #ifndef Person_h #define Person_h #include <iostream> #include <string> #include <new> using namespace std; class Person{ public: //******************Note********* //This interface is by no means complete. Please feel free to // add more functions if needed. The test cases however will only // test the following functions. virtual ~Person(); Person(); //0->SSN, "na"->name, "personal@"->personalEmail, 10->cntPlaces, allocate space to placesVisited and initializes each place to "unknown" Person operator=(const Person& rhs ); // **Minor revision**: changes the return mechanism from by-reference to by-value //copy constructor Person( const Person &clone );…arrow_forward
- Hello, I am having trouble with this homework assignment for C++ (See below for the output) 2. Implement the following: a. A class named Food. 1. dynamic data member: name 2. accessors and mutators 3. the big three b. A class named Cake that inherits from Food. 1. dynamic data member: topping (type of icing such as chocolate) 2. accessors and mutators 3. the big three c. Create an object of type Food and output its data member. d. Create an object of type Cake and output its data members. e. Test all inherited functions in main. (Cannot change the given int main. Any alteration is not accepted) int main() { cout << endl; Food f1("Bread"); f1.output(); cout << "\nf2: Copy Constructor" << endl; Food f2 = f1; f2.output(); cout << "\nf3: Assignment Overload" << endl; Food f3; f3 = f2; f3.output(); cout << "\nFood: Mutator" << endl; f1.setName("Pizza"); f2.setName("Sandwich"); f1.output(); f2.output(); f3.output(); cout << "\nCake:\n" <<…arrow_forwardUsing classes and arrays, the team will develop a set of functions for an online shopping system. The system is represented by the following structure:1- Class Item having the following private attributes: (ID, name, quantity, price) and the following public methods:- Constructors (default, parameterized, and copy)- Setters & Getters- Operator overloading for the ==, +=,-=, >> and << operators Note that the ID member variable is not entered or read from the user. It is automatically set by the class as a serial ID starting with the first item of ID 1 and incrementing with every new object.2- Class Seller having the following private attributes: (name, email, items,maxItems), where items is a dynamic array of objects of type Item with the size maxItems. The class has the following public methods:- Constructor (parameterized)- Operator overloading for the >> and << operators- Add An Item.- This will take an Item object as a parameter:- If the item already…arrow_forwardThis is in c++ The base class Pet has private data members petName, and petAge. The derived class Dog extends the Pet class and includes a private data member for dogBreed. Complete main() to: create a generic pet and print information using PrintInfo(). create a Dog pet, use PrintInfo() to print information, and add a statement to print the dog's breed using the GetBreed() function. main.cpp #include <iostream> #include<string> #include "Dog.h" using namespace std; int main() { string petName, dogName, dogBreed; int petAge, dogAge; Pet myPet; Dog myDog; getline(cin, petName); cin >> petAge; cin.ignore(); getline(cin, dogName); cin >> dogAge; cin.ignore(); getline(cin, dogBreed); // TODO: Create generic pet (using petName, petAge) and then call PrintInfo // TODO: Create dog pet (using dogName, dogAge, dogBreed) and then call PrintInfo // TODO: Use GetBreed(), to output the breed of the dog } Dog.cpp #include "Dog.h" #include…arrow_forward
- IN C++, create a class called Employee that includes three pieces of information as data members—a first name (type string), a last name (type string) and a monthly salary (type int). Your class should have a constructor that initializes the three data members. Provide a set and a get function for each data member. If the monthly salary is not positive, set it to 0. Write a test program that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10 percent raise and display each Employee’s yearly salary again.arrow_forwardHello, I am having trouble with this homework question for my c++ course. Implement a Rational Number class with the following specifications. Data members a) numerator and denominator Functions a) Constructors: 1) default constructor 2) single parameter constructor to create numerator/1 3) dual parameter constructor to create numerator/denominator 4) Use constructor delegation across all constructors. b) Accessors and Mutators for both data members. c) Static recursive GCD function using Euclid's algorithm. d) Static LCM function for two numbers. e) Reduce function simplify a rational number. This function modifies its calling object. f) Your program should work with the supplied driver program. Notes LCM (Least Common Multiple) This function returns the smallest multiple of a and b. Step 1: Multiply a and b to find a common multiple. Step 2: Divide the common multiple by the GCD of a and b. Step 3: Return the result of Step 2. Reduce: This function reduces a fraction to…arrow_forwardCan you help me please: 2. Consider the following statements: class temporary { public: void set(string, double, double); void print(); double manipulate(); void get(string&, double&, double&); void setDescription(string); void setFirst(double); void setSecond(double); string getDescription() const; double getFirst()const; double getSecond()const; temporary(string = "", double = 0.0, double = 0.0); private: string description; double first; double second; }; Now answer the following questions: a. Write the definition of the member function set so that the instance variables are set according to the parameters. b. Write the definition of the member function manipulate that returns a decimal number as follows: If the value of description is "rectangle", it returns first * second; if the value of description is "circle", it returns the area of the circle with radius first; if the value of description is "sphere", it returns the volume of the sphere with radius first; if the…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY