Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Say "Hello, World!" With C++
- #include <iostream>
- #include <cstdio>
- using namespace std;
- int main() {
- cout << "Hello, World!" << endl;
- }
- Input and Output
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- int a, b, c, sum;
- cin >> a >> b >> c;
- cout << a + b + c << endl;
- return 0;
- }
- Basic Data Types
- #include <iostream>
- #include <cstdio>
- using namespace std;
- int main() {
- int a, long b;
- return 0;
- }
- Conditional Statements
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- // Write Your Code Here
- return 0;
- }
- For Loop
- #include <iostream>
- #include <cstdio>
- using namespace std;
- int main() {
- // Complete the code.
- return 0;
- }
- Functions
- #include <iostream>
- #include <cstdio>
- using namespace std;
- /*
- Add `int max_of_four(int a, int b, int c, int d)` here.
- */
- int main() {
- int a, b, c, d;
- scanf("%d %d %d %d", &a, &b, &c, &d);
- int ans = max_of_four(a, b, c, d);
- printf("%d", ans);
- return 0;
- }
- Pointer
- #include <stdio.h>
- void update(int *a,int *b) {
- // Complete this function
- }
- int main() {
- int a, b;
- int *pa = &a, *pb = &b;
- scanf("%d %d", &a, &b);
- update(pa, pb);
- printf("%d\n%d", a, b);
- return 0;
- }
- Arrays Introduction
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
- Variable Sized Arrays
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
- StringStream
- #include <sstream>
- #include <vector>
- #include <iostream>
- using namespace std;
- vector<int> parseInts(string str) {
- // Complete this function
- }
- int main() {
- string str;
- cin >> str;
- vector<int> integers = parseInts(str);
- for(int i = 0; i < integers.size(); i++) {
- cout << integers[i] << "\n";
- }
- return 0;
- }
- Strings
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- // Complete the program
- return 0;
- }
- Structs
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- /*
- add code for struct here.
- */
- int main() {
- Student st;
- cin >> st.age >> st.first_name >> st.last_name >> st.standard;
- cout << st.age << " " << st.first_name << " " << st.last_name << " " << st.standard;
- return 0;
- }
- Class
- #include <iostream>
- #include <sstream>
- using namespace std;
- /*
- Enter code for class Student here.
- Read statement for specification.
- */
- int main() {
- int age, standard;
- string first_name, last_name;
- cin >> age >> first_name >> last_name >> standard;
- Student st;
- st.set_age(age);
- st.set_standard(standard);
- st.set_first_name(first_name);
- st.set_last_name(last_name);
- cout << st.get_age() << "\n";
- cout << st.get_last_name() << ", " << st.get_first_name() << "\n";
- cout << st.get_standard() << "\n";
- cout << "\n";
- cout << st.to_string();
- return 0;
- }
- Classes and Objects
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <cassert>
- using namespace std;
- // Write your Student class here
- int main() {
- int n; // number of students
- cin >> n;
- Student *s = new Student[n]; // an array of n students
- for(int i = 0; i < n; i++){
- s[i].input();
- }
- // calculate kristen's score
- int kristen_score = s[0].calculateTotalScore();
- // determine how many students scored higher than kristen
- int count = 0;
- for(int i = 1; i < n; i++){
- int total = s[i].calculateTotalScore();
- if(total > kristen_score){
- count++;
- }
- }
- // print result
- cout << count;
- return 0;
- }
- Box It!
- #include<bits/stdc++.h>
- using namespace std;
- //Implement the class Box
- //l,b,h are integers representing the dimensions of the box
- // The class should have the following functions :
- // Constructors:
- // Box();
- // Box(int,int,int);
- // Box(Box);
- // int getLength(); // Return box's length
- // int getBreadth (); // Return box's breadth
- // int getHeight (); //Return box's height
- // long long CalculateVolume(); // Return the volume of the box
- //Overload operator < as specified
- //bool operator<(Box& b)
- //Overload operator << as specified
- //ostream& operator<<(ostream& out, Box& B)
- void check2()
- {
- int n;
- cin>>n;
- Box temp;
- for(int i=0;i<n;i++)
- {
- int type;
- cin>>type;
- if(type ==1)
- {
- cout<<temp<<endl;
- }
- if(type == 2)
- {
- int l,b,h;
- cin>>l>>b>>h;
- Box NewBox(l,b,h);
- temp=NewBox;
- cout<<temp<<endl;
- }
- if(type==3)
- {
- int l,b,h;
- cin>>l>>b>>h;
- Box NewBox(l,b,h);
- if(NewBox<temp)
- {
- cout<<"Lesser\n";
- }
- else
- {
- cout<<"Greater\n";
- }
- }
- if(type==4)
- {
- cout<<temp.CalculateVolume()<<endl;
- }
- if(type==5)
- {
- Box NewBox(temp);
- cout<<NewBox<<endl;
- }
- }
- }
- int main()
- {
- check2();
- }
- Vector-Sort
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
- Vector-Erase
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
- Lower Bound-STL
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
- Sets-STL
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <set>
- #include <algorithm>
- using namespace std;
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
- Maps-STL
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <set>
- #include <map>
- #include <algorithm>
- using namespace std;
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
- Vector-Sort
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT */
- return 0;
- }
- Print Pretty
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main() {
- int T; cin >> T;
- cout << setiosflags(ios::uppercase);
- cout << setw(0xf) << internal;
- while(T--) {
- double A; cin >> A;
- double B; cin >> B;
- double C; cin >> C;
- /* Enter your code here */
- }
- return 0;
- }
- Inheritance Introduction
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- class Triangle{
- public:
- void triangle(){
- cout<<"I am a triangle\n";
- }
- };
- class Isosceles : public Triangle{
- public:
- void isosceles(){
- cout<<"I am an isosceles triangle\n";
- }
- //Write your code here.
- };
- int main(){
- Isosceles isc;
- isc.isosceles();
- isc.description();
- isc.triangle();
- return 0;
- }
- Rectangle Area
- #include <iostream>
- using namespace std;
- /*
- * Create classes Rectangle and RectangleArea
- */
- int main()
- {
- /*
- * Declare a RectangleArea object
- */
- RectangleArea r_area;
- /*
- * Read the width and height
- */
- r_area.read_input();
- /*
- * Print the width and height
- */
- r_area.Rectangle::display();
- /*
- * Print the area
- */
- r_area.display();
- return 0;
- }
- Multi Level Inheritance
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- class Triangle{
- public:
- void triangle(){
- cout<<"I am a triangle\n";
- }
- };
- class Isosceles : public Triangle{
- public:
- void isosceles(){
- cout<<"I am an isosceles triangle\n";
- }
- };
- //Write your code here.
- int main(){
- Equilateral eqr;
- eqr.equilateral();
- eqr.isosceles();
- eqr.triangle();
- return 0;
- }
- C++ Class Templates
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <cassert>
- using namespace std;
- /*Write the class AddElements here*/
- int main () {
- int n,i;
- cin >> n;
- for(i=0;i<n;i++) {
- string type;
- cin >> type;
- if(type=="float") {
- double element1,element2;
- cin >> element1 >> element2;
- AddElements<double> myfloat (element1);
- cout << myfloat.add(element2) << endl;
- }
- else if(type == "int") {
- int element1, element2;
- cin >> element1 >> element2;
- AddElements<int> myint (element1);
- cout << myint.add(element2) << endl;
- }
- else if(type == "string") {
- string element1, element2;
- cin >> element1 >> element2;
- AddElements<string> mystring (element1);
- cout << mystring.concatenate(element2) << endl;
- }
- }
- return 0;
- }
- Overload Operators
- //Operator Overloading
- #include<iostream>
- using namespace std;
- class Complex
- {
- public:
- int a,b;
- void input(string s)
- {
- int v1=0;
- int i=0;
- while(s[i]!='+')
- {
- v1=v1*10+s[i]-'0';
- i++;
- }
- while(s[i]==' ' || s[i]=='+'||s[i]=='i')
- {
- i++;
- }
- int v2=0;
- while(i<s.length())
- {
- v2=v2*10+s[i]-'0';
- i++;
- }
- a=v1;
- b=v2;
- }
- };
- //Overload operators + and << for the class complex
- //+ should add two complex numbers as (a+ib) + (c+id) = (a+c) + i(b+d)
- //<< should print a complex number in the format "a+ib"
- int main()
- {
- Complex x,y;
- string s1,s2;
- cin>>s1;
- cin>>s2;
- x.input(s1);
- y.input(s2);
- Complex z=x+y;
- cout<<z<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement