Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.72 KB | None | 0 0
  1. Say "Hello, World!" With C++
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. using namespace std;
  6.  
  7. int main() {
  8. cout << "Hello, World!" << endl;
  9. }
  10.  
  11. Input and Output
  12.  
  13. #include <cmath>
  14. #include <cstdio>
  15. #include <vector>
  16. #include <iostream>
  17. #include <algorithm>
  18. using namespace std;
  19.  
  20.  
  21. int main() {
  22. int a, b, c, sum;
  23. cin >> a >> b >> c;
  24. cout << a + b + c << endl;
  25. return 0;
  26. }
  27.  
  28. Basic Data Types
  29.  
  30. #include <iostream>
  31. #include <cstdio>
  32. using namespace std;
  33.  
  34. int main() {
  35. int a, long b;
  36.  
  37.  
  38. return 0;
  39. }
  40.  
  41. Conditional Statements
  42.  
  43. #include <bits/stdc++.h>
  44.  
  45. using namespace std;
  46.  
  47.  
  48.  
  49. int main()
  50. {
  51. int n;
  52. cin >> n;
  53. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  54.  
  55. // Write Your Code Here
  56.  
  57. return 0;
  58. }
  59.  
  60. For Loop
  61.  
  62. #include <iostream>
  63. #include <cstdio>
  64. using namespace std;
  65.  
  66. int main() {
  67. // Complete the code.
  68. return 0;
  69. }
  70.  
  71. Functions
  72.  
  73. #include <iostream>
  74. #include <cstdio>
  75. using namespace std;
  76.  
  77. /*
  78. Add `int max_of_four(int a, int b, int c, int d)` here.
  79. */
  80.  
  81. int main() {
  82. int a, b, c, d;
  83. scanf("%d %d %d %d", &a, &b, &c, &d);
  84. int ans = max_of_four(a, b, c, d);
  85. printf("%d", ans);
  86.  
  87. return 0;
  88. }
  89.  
  90. Pointer
  91.  
  92. #include <stdio.h>
  93.  
  94. void update(int *a,int *b) {
  95. // Complete this function
  96. }
  97.  
  98. int main() {
  99. int a, b;
  100. int *pa = &a, *pb = &b;
  101.  
  102. scanf("%d %d", &a, &b);
  103. update(pa, pb);
  104. printf("%d\n%d", a, b);
  105.  
  106. return 0;
  107. }
  108.  
  109. Arrays Introduction
  110.  
  111. #include <cmath>
  112. #include <cstdio>
  113. #include <vector>
  114. #include <iostream>
  115. #include <algorithm>
  116. using namespace std;
  117.  
  118.  
  119. int main() {
  120. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  121. return 0;
  122. }
  123.  
  124. Variable Sized Arrays
  125.  
  126. #include <cmath>
  127. #include <cstdio>
  128. #include <vector>
  129. #include <iostream>
  130. #include <algorithm>
  131. using namespace std;
  132.  
  133.  
  134. int main() {
  135. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  136. return 0;
  137. }
  138.  
  139. StringStream
  140.  
  141. #include <sstream>
  142. #include <vector>
  143. #include <iostream>
  144. using namespace std;
  145.  
  146. vector<int> parseInts(string str) {
  147. // Complete this function
  148. }
  149.  
  150. int main() {
  151. string str;
  152. cin >> str;
  153. vector<int> integers = parseInts(str);
  154. for(int i = 0; i < integers.size(); i++) {
  155. cout << integers[i] << "\n";
  156. }
  157.  
  158. return 0;
  159. }
  160.  
  161. Strings
  162.  
  163. #include <iostream>
  164. #include <string>
  165. using namespace std;
  166.  
  167. int main() {
  168. // Complete the program
  169.  
  170. return 0;
  171. }
  172.  
  173. Structs
  174.  
  175. #include <cmath>
  176. #include <cstdio>
  177. #include <vector>
  178. #include <iostream>
  179. #include <algorithm>
  180. using namespace std;
  181.  
  182. /*
  183. add code for struct here.
  184. */
  185.  
  186. int main() {
  187. Student st;
  188.  
  189. cin >> st.age >> st.first_name >> st.last_name >> st.standard;
  190. cout << st.age << " " << st.first_name << " " << st.last_name << " " << st.standard;
  191.  
  192. return 0;
  193. }
  194.  
  195. Class
  196.  
  197. #include <iostream>
  198. #include <sstream>
  199. using namespace std;
  200.  
  201. /*
  202. Enter code for class Student here.
  203. Read statement for specification.
  204. */
  205.  
  206. int main() {
  207. int age, standard;
  208. string first_name, last_name;
  209.  
  210. cin >> age >> first_name >> last_name >> standard;
  211.  
  212. Student st;
  213. st.set_age(age);
  214. st.set_standard(standard);
  215. st.set_first_name(first_name);
  216. st.set_last_name(last_name);
  217.  
  218. cout << st.get_age() << "\n";
  219. cout << st.get_last_name() << ", " << st.get_first_name() << "\n";
  220. cout << st.get_standard() << "\n";
  221. cout << "\n";
  222. cout << st.to_string();
  223.  
  224. return 0;
  225. }
  226.  
  227. Classes and Objects
  228.  
  229. #include <cmath>
  230. #include <cstdio>
  231. #include <vector>
  232. #include <iostream>
  233. #include <algorithm>
  234. #include <cassert>
  235. using namespace std;
  236.  
  237. // Write your Student class here
  238.  
  239. int main() {
  240. int n; // number of students
  241. cin >> n;
  242. Student *s = new Student[n]; // an array of n students
  243.  
  244. for(int i = 0; i < n; i++){
  245. s[i].input();
  246. }
  247.  
  248. // calculate kristen's score
  249. int kristen_score = s[0].calculateTotalScore();
  250.  
  251. // determine how many students scored higher than kristen
  252. int count = 0;
  253. for(int i = 1; i < n; i++){
  254. int total = s[i].calculateTotalScore();
  255. if(total > kristen_score){
  256. count++;
  257. }
  258. }
  259.  
  260. // print result
  261. cout << count;
  262.  
  263. return 0;
  264. }
  265.  
  266. Box It!
  267.  
  268. #include<bits/stdc++.h>
  269.  
  270. using namespace std;
  271. //Implement the class Box
  272. //l,b,h are integers representing the dimensions of the box
  273.  
  274. // The class should have the following functions :
  275.  
  276. // Constructors:
  277. // Box();
  278. // Box(int,int,int);
  279. // Box(Box);
  280.  
  281.  
  282. // int getLength(); // Return box's length
  283. // int getBreadth (); // Return box's breadth
  284. // int getHeight (); //Return box's height
  285. // long long CalculateVolume(); // Return the volume of the box
  286.  
  287. //Overload operator < as specified
  288. //bool operator<(Box& b)
  289.  
  290. //Overload operator << as specified
  291. //ostream& operator<<(ostream& out, Box& B)
  292.  
  293.  
  294. void check2()
  295. {
  296. int n;
  297. cin>>n;
  298. Box temp;
  299. for(int i=0;i<n;i++)
  300. {
  301. int type;
  302. cin>>type;
  303. if(type ==1)
  304. {
  305. cout<<temp<<endl;
  306. }
  307. if(type == 2)
  308. {
  309. int l,b,h;
  310. cin>>l>>b>>h;
  311. Box NewBox(l,b,h);
  312. temp=NewBox;
  313. cout<<temp<<endl;
  314. }
  315. if(type==3)
  316. {
  317. int l,b,h;
  318. cin>>l>>b>>h;
  319. Box NewBox(l,b,h);
  320. if(NewBox<temp)
  321. {
  322. cout<<"Lesser\n";
  323. }
  324. else
  325. {
  326. cout<<"Greater\n";
  327. }
  328. }
  329. if(type==4)
  330. {
  331. cout<<temp.CalculateVolume()<<endl;
  332. }
  333. if(type==5)
  334. {
  335. Box NewBox(temp);
  336. cout<<NewBox<<endl;
  337. }
  338.  
  339. }
  340. }
  341.  
  342. int main()
  343. {
  344. check2();
  345. }
  346.  
  347. Vector-Sort
  348.  
  349. #include <cmath>
  350. #include <cstdio>
  351. #include <vector>
  352. #include <iostream>
  353. #include <algorithm>
  354. using namespace std;
  355.  
  356.  
  357. int main() {
  358. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  359. return 0;
  360. }
  361.  
  362. Vector-Erase
  363.  
  364. #include <cmath>
  365. #include <cstdio>
  366. #include <vector>
  367. #include <iostream>
  368. #include <algorithm>
  369. using namespace std;
  370.  
  371.  
  372. int main() {
  373. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  374. return 0;
  375. }
  376.  
  377. Lower Bound-STL
  378.  
  379. #include <cmath>
  380. #include <cstdio>
  381. #include <vector>
  382. #include <iostream>
  383. #include <algorithm>
  384. using namespace std;
  385.  
  386.  
  387. int main() {
  388. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  389. return 0;
  390. }
  391.  
  392. Sets-STL
  393.  
  394. #include <cmath>
  395. #include <cstdio>
  396. #include <vector>
  397. #include <iostream>
  398. #include <set>
  399. #include <algorithm>
  400. using namespace std;
  401.  
  402.  
  403. int main() {
  404. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  405. return 0;
  406. }
  407.  
  408. Maps-STL
  409.  
  410. #include <cmath>
  411. #include <cstdio>
  412. #include <vector>
  413. #include <iostream>
  414. #include <set>
  415. #include <map>
  416. #include <algorithm>
  417. using namespace std;
  418.  
  419.  
  420. int main() {
  421. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  422. return 0;
  423. }
  424.  
  425. Vector-Sort
  426.  
  427. #include <cmath>
  428. #include <cstdio>
  429. #include <vector>
  430. #include <iostream>
  431. #include <algorithm>
  432. using namespace std;
  433.  
  434.  
  435. int main() {
  436. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  437. return 0;
  438. }
  439.  
  440. Print Pretty
  441.  
  442. #include <iostream>
  443. #include <iomanip>
  444. using namespace std;
  445.  
  446. int main() {
  447. int T; cin >> T;
  448. cout << setiosflags(ios::uppercase);
  449. cout << setw(0xf) << internal;
  450. while(T--) {
  451. double A; cin >> A;
  452. double B; cin >> B;
  453. double C; cin >> C;
  454.  
  455. /* Enter your code here */
  456.  
  457. }
  458. return 0;
  459.  
  460. }
  461.  
  462. Inheritance Introduction
  463.  
  464. #include <cmath>
  465. #include <cstdio>
  466. #include <vector>
  467. #include <iostream>
  468. #include <algorithm>
  469. using namespace std;
  470.  
  471.  
  472. class Triangle{
  473. public:
  474. void triangle(){
  475. cout<<"I am a triangle\n";
  476. }
  477. };
  478.  
  479. class Isosceles : public Triangle{
  480. public:
  481. void isosceles(){
  482. cout<<"I am an isosceles triangle\n";
  483. }
  484. //Write your code here.
  485. };
  486.  
  487. int main(){
  488. Isosceles isc;
  489. isc.isosceles();
  490. isc.description();
  491. isc.triangle();
  492. return 0;
  493. }
  494.  
  495. Rectangle Area
  496.  
  497. #include <iostream>
  498.  
  499. using namespace std;
  500. /*
  501. * Create classes Rectangle and RectangleArea
  502. */
  503.  
  504.  
  505. int main()
  506. {
  507. /*
  508. * Declare a RectangleArea object
  509. */
  510. RectangleArea r_area;
  511.  
  512. /*
  513. * Read the width and height
  514. */
  515. r_area.read_input();
  516.  
  517. /*
  518. * Print the width and height
  519. */
  520. r_area.Rectangle::display();
  521.  
  522. /*
  523. * Print the area
  524. */
  525. r_area.display();
  526.  
  527. return 0;
  528. }
  529.  
  530. Multi Level Inheritance
  531.  
  532. #include <cmath>
  533. #include <cstdio>
  534. #include <vector>
  535. #include <iostream>
  536. #include <algorithm>
  537. using namespace std;
  538.  
  539. class Triangle{
  540. public:
  541. void triangle(){
  542. cout<<"I am a triangle\n";
  543. }
  544. };
  545.  
  546. class Isosceles : public Triangle{
  547. public:
  548. void isosceles(){
  549. cout<<"I am an isosceles triangle\n";
  550. }
  551. };
  552.  
  553. //Write your code here.
  554.  
  555. int main(){
  556.  
  557. Equilateral eqr;
  558. eqr.equilateral();
  559. eqr.isosceles();
  560. eqr.triangle();
  561. return 0;
  562. }
  563.  
  564. C++ Class Templates
  565.  
  566. #include <cmath>
  567. #include <cstdio>
  568. #include <vector>
  569. #include <iostream>
  570. #include <algorithm>
  571. #include <cassert>
  572. using namespace std;
  573.  
  574. /*Write the class AddElements here*/
  575.  
  576. int main () {
  577. int n,i;
  578. cin >> n;
  579. for(i=0;i<n;i++) {
  580. string type;
  581. cin >> type;
  582. if(type=="float") {
  583. double element1,element2;
  584. cin >> element1 >> element2;
  585. AddElements<double> myfloat (element1);
  586. cout << myfloat.add(element2) << endl;
  587. }
  588. else if(type == "int") {
  589. int element1, element2;
  590. cin >> element1 >> element2;
  591. AddElements<int> myint (element1);
  592. cout << myint.add(element2) << endl;
  593. }
  594. else if(type == "string") {
  595. string element1, element2;
  596. cin >> element1 >> element2;
  597. AddElements<string> mystring (element1);
  598. cout << mystring.concatenate(element2) << endl;
  599. }
  600. }
  601. return 0;
  602. }
  603.  
  604. Overload Operators
  605.  
  606. //Operator Overloading
  607.  
  608. #include<iostream>
  609.  
  610. using namespace std;
  611.  
  612. class Complex
  613. {
  614. public:
  615. int a,b;
  616. void input(string s)
  617. {
  618. int v1=0;
  619. int i=0;
  620. while(s[i]!='+')
  621. {
  622. v1=v1*10+s[i]-'0';
  623. i++;
  624. }
  625. while(s[i]==' ' || s[i]=='+'||s[i]=='i')
  626. {
  627. i++;
  628. }
  629. int v2=0;
  630. while(i<s.length())
  631. {
  632. v2=v2*10+s[i]-'0';
  633. i++;
  634. }
  635. a=v1;
  636. b=v2;
  637. }
  638. };
  639.  
  640. //Overload operators + and << for the class complex
  641. //+ should add two complex numbers as (a+ib) + (c+id) = (a+c) + i(b+d)
  642. //<< should print a complex number in the format "a+ib"
  643.  
  644. int main()
  645. {
  646. Complex x,y;
  647. string s1,s2;
  648. cin>>s1;
  649. cin>>s2;
  650. x.input(s1);
  651. y.input(s2);
  652. Complex z=x+y;
  653. cout<<z<<endl;
  654. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement