Question: Explain why the code shown below, when executed, will print the value 420. #include #define init_employee(X,Y) {(X),(Y),wage_emp} typedef struct Employee Em; struct Employee {int hours,salary;int
Explain why the code shown below, when executed, will print the value 420.
#include #define init_employee(X,Y) {(X),(Y),wage_emp}
typedef struct Employee Em;
struct Employee {int hours,salary;int (*wage)(Em*);};
int wage_emp(Em *ths) {return ths->hours*ths->salary;}
#define init_manager(X,Y,Z) {(X),(Y),wage_man,(Z)}
typedef struct Manager Mn;
struct Manager {int hours,salary;int (*wage)(Mn*);int bonus;}; int wage_man(Mn *ths) {return ths->hours*ths->salary+ths->bonus;}
int main(void) {
Mn m = init_manager(40,10,20);
Em *e= (Em *) &m;
printf("%d ",e->wage(e));
return 0; }
(c) Rewrite the C code shown in part (b) using C++ primitives a
can't seem to get this code to work:
#ifndef CSVPARSER_HPP
# define CSVPARSER_HPP
# include
# include
# include
# include
# include
namespace csv
{
class Error : public std::runtime_error
{
public:
Error(const std::string &msg):
std::runtime_error(std::string("CSVparser : ").append(msg))
{
}
};
class Row
{
public:
Row(const std::vector
~Row(void);
public:
unsigned int size(void) const;
void push(const std::string &);
bool set(const std::string &, const std::string &);
private:
const std::vector
std::vector
public:
template
const T getValue(unsigned int pos) const
{
if (pos < _values.size())
{
T res;
std::stringstream ss;
ss << _values[pos];
ss >> res;
return res;
}
throw Error("can't return this value (doesn't exist)");
}
const std::string operator[](unsigned int) const;
const std::string operator[](const std::string &valueName) const;
friend std::ostream& operator<<(std::ostream& os, const Row &row);
friend std::ofstream& operator<<(std::ofstream& os, const Row &row);
};
enum DataType {
eFILE = 0,
ePURE = 1
};
class Parser
{
public:
Parser(const std::string &, const DataType &type = eFILE, char sep = ',');
~Parser(void);
public:
Row &getRow(unsigned int row) const;
unsigned int rowCount(void) const;
unsigned int columnCount(void) const;
std::vector
const std::string getHeaderElement(unsigned int pos) const;
const std::string &getFileName(void) const;
public:
bool deleteRow(unsigned int row);
bool addRow(unsigned int pos, const std::vector
void sync(void) const;
protected:
void parseHeader(void);
void parseContent(void);
private:
std::string _file;
const DataType _type;
const char _sep;
std::vector
std::vector
std::vector
public:
Row &operator[](unsigned int row) const;
};
}
Write program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. write program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.
Write method reverse that takes an array as an argument and reverses it.
Give complete definition of UpdatableTreeSet that overrides the inherited methods boolean add(SubscribableStudentInfo) and boolean remove(Object) to automatically subscribe and unsubscribe to their arguments, as appropriate.
A game designer wishes to store all the game preferences (e.g., player name, screen size, music volume, etc.) within a custom Preference class. (i) Assuming each preference is stored as a unique String key mapping to a String value, give a simple implementation of Preference that allows for efficiently setting or updating preferences and retrieving previously set ones.
provide answers to all questions above
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
