what\'s wrong with programming? #include <iostream> #include <string> using nams
ID: 3841005 • Letter: W
Question
what's wrong with programming?
#include <iostream>
#include <string>
using namspace std;
struct names {
string first;
string last;
};
int main() {
names.customer = "Smith", "Orley";
cout << name.first << endl;
cout << names.last << endl;
return 0;
}
-------------------------
struct ThreeVals {
int a, b, c;
};
int main () {
TwoVals s, *sptr = nullptr;
*sptr.a = 1;
return 0;
}
--------------------------
struct Values {
string name;
int age;
}
-------------------
#include <iostream>
using namespace std;
class DumBell;
{
int wekght;
public:
void setWeight(int);
}
void setWeight(int w)
{
Weight = w;
}
int main()
{
DumBell bar;
DumBell(200);
cout << "The weight is " << bar.weight << endl;
return 0;
}
--------------------
class Change
{
public:
int pennies;
int nickels;
int dimes;
int quarters;
Change()
{
pennies = nickels = dimes = quarters = 0;
}
Change(int p = 100; int n = 50, d = 50, q = 25);
};
void Change::Change(int p, int n , d, q)
{
pennies = p;
nickels = n;
dimes = d;
quarters = q;
}
------------------
class Box
{
private:
double width;
double length;
double height;
public:
Box(double w, l, h)
{
width = w; length = l; height = h;
}
Box(Box b) // Copy constructor
{
width = b.width;
length = b.length;
height = b.height;
... Other member functions follow ...
};
---------------------
class Circle
{
private:
double diameter;
int centerX;
int centerY;
public:
Circle(double d, int x, int y)
{
diameter = d; centerX = x; centerY = y;
}
// Overloaded = operator
void Circle = (Circle &right)
{
diameter = right.diameter;
centerX = right.centerX;
centerY = right.centerY;
}
... Other member functions follow ...
};
-----------------
class Box
{
private:
double width;
double length;
double height;
public:
Box(double w, l, h)
{
width = w; length = l; height = h;
}
// Overloaded prefix ++ operator
void operator++()
{ ++width; ++length; }
// Overloaded postfix ++ operator
void operator++()
{ width++; length++; }
... Other member functions follow ...
};
-----------------
class Car, public Vehicle
{
public:
Car();
~Car();
protected:
int passengers;
}
---------------
Class Table : public Furniture
{
protected:
int numSeats;
public:
Table (int n) : Furniture (numSeats)
{
numSeats = n;
}
~Table();
}
Explanation / Answer
//prog1
#include <iostream>
#include <string>
using namespace std;
struct names {
string first;
string last;
};
int main() {
names customer = {"Smith", "Orley"};
cout << customer.first << endl;
cout << customer.last << endl;
return 0;
}
OUTPUT:
Smith
Orley
//prog2
#include<iostream>
using namespace std;
struct ThreeVals
{
int a, b, c;
};
int main ()
{
ThreeVals s , *sptr;
sptr=&s;
(*sptr).a = 1;
return 0;
}
//prog3
#include<iostream>
#include<string>
using namespace std;
struct Values {
string name;
int age;
};
//prog4
#include <iostream>
using namespace std;
class DumBell
{
private:
int weight;
public:
DumBell(int w)
{
weight=w;
}
int getWeight()
{
return weight;
}
void setWeight(int w)
{
weight = w;
}
};
int main()
{
DumBell bar(200);
cout << "The weight is " << bar.getWeight() << endl;
return 0;
}
OUTPUT:
The weight is 200
//prog5
#include <iostream>
using namespace std;
class Change
{
public:
int pennies;
int nickels;
int dimes;
int quarters;
Change()
{
pennies = nickels = dimes = quarters = 0;
}
Change(int p = 100, int n = 50, int d = 50, int q = 25);
};
Change::Change(int p, int n ,int d, int q)
{
pennies = p;
nickels = n;
dimes = d;
quarters = q;
}
int main()
{
return 0;
}
Note : please post for remaining things
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.