1. Define a structure named StockItem with two string fields,
supplier and productName and one int field, catalogNumber. Then
define a structure named Customer with string fields name,
streetAddress, city, postalCode, phone. Assume that structures
named Date and Money have already been defined (representing a date
and a monetary amount respectively.
Finally, define a structure named Purchase that has these fields:
buyer of type Customer, itemSold of type StockItem, dateOfSale of
type Date, paid of type Money, returnable of type bool.
2. In mathematics, the distance between one point (A) and another
point (B), each with coordinates (x,y), can be computed by taking
the differences of their x coordinates and their y coordinates and
then squaring those differences. The squares are added and the
square root of the resulting sum is taken and... voila! The
distance. Assume that Point has already been defined as a
structured type with two double fields, x and y. Define a function
dist that takes two Point arguments and returns the distance
between the points they represent.
3. Assume that Point has already been defined as a structured type
with two double fields, x and y. Write a function, getPoint that
returns a Point value whose fields it has just read in from
standard input. Assume the value of x precedes the value of y in
the input.
Prgram 1:
Definition of each structure is given below along with comments.
// Definition of the structure Date.
struct Date
{
char date[SIZE];
};
// Definition of the structure Money.
struct Money
{
char amount[SIZE];
};
// Definition of the structure StockItem.
struct StockItem
{
// Declare variables.
char supplier[SIZE];
char productName[SIZE];
int catalogNumber;
};
// Definition of the structure Customer.
struct Customer
{
// Declare member variables.
char name[SIZE], streetAdress[SIZE], city[SIZE];
int postalCode;
int phoneNumber;
};
// Definition of the structure Purchase.
struct Purchase
{
// Declare the variable buyer of the
// type structure Customer.
Customer buyer;
// Declare the variable itemSold of the
// type structure StockItem.
StockItem itemSold;
// Declare the variable dateOfSale of the
// type structure date.
Date dateOfSale;
// Declare the variable paid of the
// type structure Money.
Money paid;
// Boolean function of the type structure Purchase.
bool get()
{
return 0;
}
};
To test the above stuctures the below program is provided.
Program code:
#include "stdafx.h"
#include
const int SIZE = 20;
// Definition of the structure Date.
struct Date
{
char date[SIZE];
};
// Definition of the structure Money.
struct Money
{
char amount[SIZE];
};
// Definition of the structure StockItem.
struct StockItem
{
// Declare variables.
char supplier[SIZE];
char productName[SIZE];
int catalogNumber;
};
// Definition of the structure Customer.
struct Customer
{
// Declare member variables.
char name[SIZE], streetAdress[SIZE], city[SIZE];
int postalCode;
int phoneNumber;
};
// Definition of the structure Purchase.
struct Purchase
{
// Declare the variable buyer of the
// type structure Customer.
Customer buyer;
// Declare the variable itemSold of the
// type structure StockItem.
StockItem itemSold;
// Declare the variable dateOfSale of the
// type structure date.
Date dateOfSale;
// Declare the variable paid of the
// type structure Money.
Money paid;
// Boolean function of the type structure Purchase.
bool get()
{
return 0;
}
};
int main()
{
bool flag;
Purchase p;
// call the method of bool type from the structure Purchase
// which returns a Boolean value.
flag = p.get();
std::cout << flag << "\n";
system("pause");
// Returns a Boolean value
return flag;
}
Sample Output:
Program 2:
Definition of the function dist that takes two Point arguments and returns the distance between the points:
Note: I have tested this function using the program.
Complete program code to test the above function:
Sample Output:
Complete program code to copy:
#include "stdafx.h"
#include
#include
#include
using namespace std;
//Point structure
struct Point
{
public:
double x;
double y;
};
// Funtion prototype.
double dist(Point, Point);
// Definition of the function
double dist(Point temp1, Point temp2)
{
double power1, power2, diff;
// Find the difference between x coordinates and y coordinates
// and then square the differences.
power1 = pow((temp1.x - temp2.x), 2);
power2 = pow((temp1.y - temp2.y), 2);
// Add the sqaures.
diff = power1 + power2;
// Apply sqaure root to the sum.
diff = sqrt(diff);
// Return the distance between the points.
return diff;
}
// Definition of the main() function.
int main()
{
Point p1, p2;
cout<<"Enter point A
(x1,y1)."< cout << "Enter x1-value: "; cin >> p1.x; cout << "Enter y1-value: "; cin >> p1.y; cout<<"Enter point B
(x2,y2)."< cout << "Enter x2-value: "; cin >> p2.x; cout << "Enter y2-value: "; cin >> p2.y; cout << setprecision(2) << "Distance between"
<< "("<< p1.x << "," << p1.y << ")
and" << "(" << p2.x << "," << p2.y << ") is"
<< distancexy(p1, p2)< system("pause"); return 0; } Progarm 3: Definition of the structure Point and the function
getPoint(): Note: i have tested this function using the
program. Complete progarm code to test the above
function: Sample output: Complete program code to copy: #include "stdafx.h" #include using namespace std; // Define structure Point. struct Point { double x; double y; }; // Definition of the function getPoint(). struct Point getPoint() { struct Point a; //Read the Point value. cout << "Enter x value of the
point: "; cin >> a.x; cout << "Enter y value of the
point: "; cin >> a.y; // Return the Point value. return a; } // Define main() function. int main() { // Create an object a of type structure
Point. struct Point p; // Call the function getPoint(). p = getPoint(); // Print the Point value cout << "The point is: " <<
"(" << p.x << "," << p.y
<< ")" << endl; system("pause"); return 0; }
1. Define a structure named StockItem with two string fields, supplier and productName and one int field, catalogNumber. Then define a structure named Customerwith string fields name, streetAddress, city, postalCode, phone. Assume that structures named Date and Money have already been defined (representing a date and amonetary amount respectively.Finally, define a structure named Purchase that has these fields: buyer of type Customer, itemSold of type StockItem, dateOfSale of type Date, paid of type Money,returnable of type bool.2. In mathematics, the...
Hello! This is C++.
Q3. Write a program
Define a Super class named Point
containing:
An instance variable named x of type
int.
An instance variable named y of type
int.
Declare a method named toString() Returns a
string representation of the point.
Constructor that accepts values of all data
members as arguments.
Define a Sub class named Circle. A
Circle object stores a radius (double) and inherit
the (x, y) coordinates of its center from its super class Point....
Given a type Money that is a structured type with two int fields, dollars and cents. Assume that an array named monthlySales with 12 elements, each of type Money has been declared and initialized.
Assume that a Money variable yearlySales has also been declared. Write the necessary code that traverses the monthlySales array and adds it all up and stores the resulting total in yearlySales. Be sure make sure that yearlySales ends up with a valid value, i.e. a value...
C++
1. Your program should use named string constant for the file name
to open the file. Do not add any path to the file name because the
path on your computer is not likely to exist on the computer the
instructor uses to grade the program. Points may be deducted if you
don't follow this instruction.
2. Split statements and comments longer than 80 characters into
multiple lines and use proper indentations for the split
portions.
(Lab2b.cpp) Write a...
NEEDS TO BE IN PYTHON:
(The Point class)
Design a class named Point to represent a point with x-
and y-coordinates. The class contains:
- Two private data fields x and y that
represent the coordinates with get methods.
- A constructor that constructs a point with specified coordinates,
with default point (0, 0).
- A method named distance that returns the distance from this point
to another point of the Point type.
- A method named isNearBy(p1) that returns...
Inheritance Problem: (C++)
(The MyPoint class) Design a class named MyPoint to represent a
point with x-and y-coordinates. The class contains:
Two data fields x and y that represent the coordinates.
A no-arg constructor that creates a point (0, 0).
A constructor that constructs a point with specified coordinates
using passed in arguments.
Two get functions for data fields x and y, respectively.
A method named distance that returns the distance from this point
to another point of the MyPoint...
Add Answer to:
1. Define a structure named StockItem with two string fields, supplier and productName and one int field, catalogNumber...
Structures as Function of C++ (myprogramminglab.com assignment)
Hello! This is C++.
Q3. Write a program
Define a Super class named Point
containing:
An...
Given a type Money that is a structured type with two int fields, dollars and cents. Assume that an array named monthlyS...
C++
1. Your program should use named string constant for the file name
to open the...
NEEDS TO BE IN PYTHON:
(The Point class)
Design a class named Point to represent a...
Inheritance Problem: (C++)
(The MyPoint class) Design a class named MyPoint to represent a
point with...
Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the c...
C++
Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...
Please answer all the questions
2. Design two programs named BaseClass and SubClass. In BaseClass, define...
Please answer all the questions
2. Design two programs named BaseClass and SubClass. In BaseClass, define a variable xVar (type: char, value: 65), and a method myPrint to print xVar. SubClass is a subclass of BaseClass. In SubClass, define a variable yVar (type: int, value: 16) and another variable strVar (type: String, value: "java program!"). There is also a method myPrint to print the value of yVar and strVar in SubClass, as well as an additional method printAll, in which...
Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in thr...
Draw the UML DIAGRAM ALSO
PLEASE DRAW THE UML DIAGRAM.ALSO
in java
should use the program in java
For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...