Beruflich Dokumente
Kultur Dokumente
Assignment 7
Program 1
#include <iostream>
#include <string>
using namespace std;
double balance;
/**
Turns digit into its English name,
@param n integer between 1 and 9
@ return th ename of n ("one"... ("nine")
*/
/**
Given the English name of a multiple of 10,
@param n an integer between 2 and 9
@return the name of n ("twenty"... ("ninety")
*/
string tens_name (int n)
{
if (n == 2) return " twenty";
if (n == 3) return "thirty";
if (n == 4) return "forty";
if (n == 5) return "fifty";
if (n == 6) return "sixty";
if (n == 7) return "seventy";
if (n == 8) return "eighty";
if (n == 9) return "ninety";
return "";
*/
string int_name (int n)
{
{
r = int_name (c/1000) + " thousand";
c = c % 1000;
}
if (c >= 100)
{
r = r + " " + digit_name(c/ 100) + "hundred";
c = c % 100;
}
if (c >= 10)
{
r = r + " " +tens_name (c/ 10);
c = c % 10;
}
if (c>=10)
{
r = r + " " + teen_name (c);
c = 0;
}
if (c > 0)
r = r + " " + digit_name(c);
return r;
}
int main ()
{
int n;
cout << "please enter a positive integer: " ;
cin >> n;
cout << int_name (n);
return 0;
}
Program 2
#include <iostream>
#include <string>
int main ()
{
string best_name = " ";
double best_price = 1;
int best_score = 0;
return 0;
Program 3
#include <iostream>
#include <string>
class Product
public:
/**
*/
Product();
/**
*/
void read();
/**
*/
/**
*/
private:
string name;
double price;
int score;
};
Product::Product()
{
price = 1;
score = 0;
}
void Product::read()
getline(cin, name);
getline(cin, remainder);
}
void Product::print() const
Product best;
while (more)
Product next;
next.read();
if (next.is_better_than(best))
best = next;
string answer;
getline(cin, answer);
if (answer != "y")
more = false;
best.print();
return 0;