#include<iostream>
#include<string>
#include<vector>
#include<cctype>
#include<initializer_list>
#include<istream>
#include<fstream>
using std::istream;
using std::ostream;
using std::string;
using std::cin;
using std::cout;
using std::endl;
using std::getline;
using std::size;
using std::empty;
using std::vector;
using std::begin;
using std::end;
using std::initializer_list;
typedef string::size_type sz;
using F = int(int*, int);
using PF = int(*)(int*, int);
string screen(sz ht = 24, sz wid = 80, char backgrnd = ' ');
string screen1(sz sd=12 , sz ed=78, char=' ');
bool lengthcompare(const string &, const string &);
int fact(int cc);
void reset(int *p);
void re(int &i);
void print(const int *beg, const int *end);
void printtt(const int ia[10]);
const string &shortS(const string &s1, const string &s2);
string &shortSt(string &s1, string &s2);
char &get_val(string &str, string::size_type ix);
int main() {
cout << "enter two numbers,please" << endl;
int v1, v2;
cin >> v1 >> v2;
cout << "the sum of " << v1 << "and " << v2 << "is " << v1 + v2 << endl;
string s;
while (getline(cin,s))
if(s.size()>3)
cout << s << endl;
string ass = "sad ";
string fd = ass + ", ";
string ed = ", ";
string gd = ed + ", ";
string v("sdsafa asdfasw ew");
for (auto c : v)
cout << c << endl;
string ds = "hello world!!!@";
decltype(ds.size()) punct_cnt = 0;
for (auto c : ds)
if (ispunct(c))
++punct_cnt;
cout << punct_cnt << "\n" << ds << endl;
string rd("dsfa ef!!");
for (auto &c : rd)
c = toupper(c);
cout << rd << endl;
const string sixteen ("0123456789ABCDEF");
cout << "enter a series of numbers" << endl;
string result;
string::size_type n;
while (cin >> n)
if (n < sixteen.size())
result += sixteen[n];
cout << result << endl;
string es("sde efrf");
for (auto &c : es)
if(!es.empty())
c = 'x';
cout << es << endl;
vector <string>art = { "ss" , "ds","df"};
vector<string>aw(art);
vector<int>qwer(12, -2);
vector<int>eddc(12, 3);
vector<string>ws(12, "dew");
vector<string>ed(12);
vector<int>wws{ 10,1 };
vector<int>wse(10, 1);
vector<int>was(10);
vector<int>wqw{ 10 };
vector<string>qwe{ 10,"ws" };
int ww;
vector<int>tr;
while (cin>>ww)
{
tr.push_back(ww);
}
vector<string>wx{ "wdew","ws","wsc" };
for (auto i : wx)
cout << i << " ";
vector<unsigned>score(11, 0);
unsigned grade;
while (cin >> grade)
{
if (grade <= 100)
++score[grade / 10];
}
vector<int>we;
we.push_back(10);
int sad = fact(4);
cout << sad << endl;
int i = 42;
reset(&i);
cout << i << endl;
int j = 42;
re(j);
cout << j << endl;
int j[2] = {0,1};
print(begin(j), end(j));
int j[10] = { 0,1,2,3,4,8,21,12,23,};
printtt(j);
string aa = shortS("dsfs", "dsdaewde");
cout << aa << endl;
string suv("a value");
cout << suv << endl;
get_val(suv, 0) = 'A';
cout << suv << endl;
screen(66);
bool(*pf)(const string&, const string &);
pf = lengthcompare;
bool b1 = pf("hello ", "sadew");
bool b2 = (*pf)("sd", "ewdfew");
bool b3 = lengthcompare("wde", "wedf");
Sales_data total;
Screen::pos ht = 24, wd = 80;
Screen scr(ht, wd, ' ');
Screen *p = &scr;
char c = scr.get();
c = p->get();
string rf = screen1(23, 34);
double r;
r = account::rate();
account ac1;
account *ac2 = &ac1;
r = ac1.rate();
r = ac2->rate();
auto old_state = cin.rdstate();
cin.clear();
cin.setstate(old_state);
system("pause");return 0;
}
int fact(int cc) {
int co = 1;
while (cc>1)
{
co *= cc--;
}
return co;
}
void reset(int *p) {
*p = 0;
p = 0;
}
void re(int &i)
{
i = 0;
}
void print(const int *beg, const int *end) {
while (beg!=end)
{
cout << *beg++ << endl;
}
}
void printt(const int ia[], size_t size) {
for (size_t i = 0; i != size; ++i) {
cout << ia[i] << endl;
}
}
void printtt(const int ia[10]) {
for (size_t i = 0; i != 10; ++i) {
cout << ia[i] << endl;
}
}
void error_msg(initializer_list<string> i1) {
for (auto beg = i1.begin(); beg != i1.end(); ++beg) {
cout << *beg << " ";
cout << endl;
}
}
void swap(int &a, int &b) {
if (a == b)
return;
else
{
int temp = a;
a = b;
b = temp;
}
}
const string &shortS(const string &s1, const string &s2) {
return s1.size() <= s2.size() ? s1 : s2;
}
string &shortSt(string &s1, string &s2) {
return s1.size() <= s2.size() ? s1 : s2;
}
char &get_val(string &str, string::size_type ix) {
return str[ix];
}
int mul(int val) {
if (val > 1)
return mul(val - 1)*val;
return 1;
}
void print(int &a, string &b) {
cout << a << " " << b << endl;
}
typedef string::size_type sz;
string screen(sz , sz , char ) {
return 0;
}
inline string screen1(sz, sz, char) {
}
constexpr int cd = 23;
constexpr int new_pr() { return 42; }
constexpr int foo = new_pr();
void f(int) {
}
void f(int, int) {
}
void f(double t, double tz) {
}
bool lengthcompare(const string &, const string &) { return 0; }
void usebigger(const string &s1, const string &s2, bool pf(const string &, const string &)) {}
void usebiggerr(const string &s1, const string &s2, bool *pf(const string &, const string &)) {}
PF f1(int){}
F *f2(int){}
struct Sales_data
{
public://这两个叫做访问说明符 public允许在整个程序访问
Sales_data() = default;
Sales_data(const string &s):bookNo(s){}
Sales_data(const string &s,unsigned n,double p)://所有定义在类内部的函数自动是inline滴
bookNo(s),units_sold(n),revenue(p*n){}
Sales_data(istream &);
string isdn()const { return bookNo; }
Sales_data& combine(const Sales_data&);
double avg_price()const;
private://而private只允许被类的成员函数调用访问(封装在内部啦)danshi这样的话辅助函数add和print也没法访问了 然后看有缘friend
string bookNo;
unsigned units_sold = 0;
double revenue = 0.0;
friend Sales_data add(const Sales_data&, const Sales_data&);
friend istream &read(istream&, Sales_data&);
friend ostream &print(ostream&, const Sales_data&);
};
Sales_data add(const Sales_data&, const Sales_data&);
ostream &print(ostream &, const Sales_data&);
istream &read(istream&, Sales_data&);
double Sales_data::avg_price()const {
if (units_sold)return revenue / units_sold;
else
return 0;
}
istream &read(istream &is, Sales_data &item) {
double price = 0;
is >> item.bookNo >> item.units_sold >> price;
item.revenue = price * item.units_sold;
return is;
}
ostream &print(ostream &os, const Sales_data &item) {
os << item.isdn() << " " << item.units_sold << " " <<
item.revenue << " " << item.avg_price();
return os;
}
Sales_data add(const Sales_data &lhs, const Sales_data &rhs) {
Sales_data sum = lhs;
sum.combine(rhs);
return sum;
}
Sales_data::Sales_data(istream &is) { read(is, *this); }
class Screen {
public:
friend class window_mgr;
typedef string::size_type pos;
Screen() = default;
Screen(pos ht,pos wd,char c):height(ht),width(wd),contents(ht*wd,c){}
char get()const { return contents[cursor]; }
inline char get(pos ht, pos wd)const;
Screen &move(pos r, pos c);
Screen &set(char);
Screen &set(pos, pos, char);
Screen &display(ostream &os) { do_display(os); return *this; }
const Screen &display(ostream &os)const { do_display(os); return *this; }
private:
pos cursor = 0;
pos height = 0, width = 0;
string contents;
void do_display(ostream &os) const { os << contents; }
};
inline
Screen &Screen::move(pos r, pos c) {
pos row = r * width;
cursor = row + c;
return *this;
}
char Screen::get(pos r, pos c)const {
pos row = r * width;
return contents[row + c];
}
class screen {
public:
void some_member() const ;
private:
mutable size_t access_ctr;
};
void screen::some_member()const {
++access_ctr;
}
class window_mgr {
public:
using ScreenIndex = vector<Screen>::size_type;
void clear(ScreenIndex);
private:
vector<Screen>screens{ Screen(24,80,' ') };
};
void window_mgr::clear(ScreenIndex i) {
Screen &s = screens[i];
s.contents = string(s.height*s.width, ' ');
}
inline Screen &Screen::set(char c) {
contents[cursor] = c;
return *this;
}
inline Screen &Screen::set(pos r, pos col, char ch) {
contents[r*width + col] = ch;
return *this;
}
class student;
Sales_data aa;
struct Sales_data as;
class link_screen {
Screen window;
link_screen *next;
link_screen &asd;
};
class X {
int i;
int j;
private:
X(int val):j(val),i(j){}
};
class account {
public:
void calculate() { amount += amount * interestRate; }
static double rate() { return interestRate; }
static void rate(double);
private:
string owner;
double amount;
static double interestRate;
static double initRate();
};
void account::rate(double newrate) {
interestRate = newrate;
}
double account::interestRate = initRate();