Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Answer No.1: Code<
- #include<iostream>
- using namespace std;
- int main()
- {
- double c,f;
- cout<<"\tCelcius\t\tFarenheit\n";
- for(c=10;c<=18;c+=4)
- {
- f=((c*9)/5)+32;
- cout<<"\t"<<c<<"\t\t"<<f<<endl;
- }
- return 0;
- }
- Output:
- Answer No:2.
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- { string a="`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./";
- string s;
- getline(cin,s);
- for(int i=0; i<=s.size(); i++)
- { for(int j=0; j<=a.size()-1; j++)
- { if(s[i]==a[j])
- { cout<<a[j-2]; break; }
- else if(s[i]==' ')
- { cout<<" ";
- break; } } }
- cout<<endl;
- }
- Output:
- Answer No: 3.Convert into number:
- #include <iostream>
- #include <vector> // std::vector
- #include <algorithm> // std::reverse
- const std::vector<std::string> first_twenty_vocabular = {
- "zero ","one ","two ","three ","four ","five ","six ","seven ","eight ","nine ","ten ",
- "eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ",
- "nineteen " };
- const std::vector<std::string> magnitude_vocabular = {
- "hundred ","thousand ","million ", "billion "};
- const std::vector<std::string> decine_vocabular = {
- "twenty ", "thirty ", "fourty ", "fifty ", "sixty ", "seventy ","eighty ","ninety "};
- std::string Stringer(std::vector<int> src);
- std::string MagnitudeSplitter(std::vector<int> src);
- std::vector<int> VectorSplitter(std::vector<int> &V);
- std::string units(std::vector<int> src);
- std::string decine(std::vector<int> src);
- )
- std::string hundreds(std::vector<int> src);
- void FlipVector(std::vector<int>& V) {
- std::reverse(V.begin(), V.end());
- }
- void PrintVector(std::vector<int> v) {
- int len = v.size();
- for (int i = 0; i < len; ++i) { std::cout << v[i];}
- std::cout << std::endl;
- }
- std::vector<int> Splitter(int src_num) {
- std::vector<int> v_Digits;
- if (src_num == 0) {
- v_Digits.push_back(0);
- return v_Digits;
- }
- else {
- while(src_num >= 10) {
- v_Digits.push_back(src_num%10);
- src_num /= 10;
- }
- v_Digits.push_back(src_num);
- return v_Digits;
- }
- }
- std::string units(std::vector<int> src) {
- std::string uni_str = first_twenty_vocabular[src[0]];
- return uni_str;
- }
- std::string decine(std::vector<int> src) {
- std::string dec_str = "";
- if (src[0] == 0) {
- if (src[1] == 0) { return dec_str; }
- else {
- dec_str.append(first_twenty_vocabular[src[1]]);
- return dec_str;
- }
- }
- else if (src[0] == 1) {
- dec_str.append(first_twenty_vocabular[10+src[1]]);
- return dec_str;
- }
- else {
- dec_str.append(decine_vocabular[src[0]-2]);
- if(src[1] == 0) { return dec_str; }
- else {
- dec_str.append(first_twenty_vocabular[src[1]]);
- return dec_str;
- }
- }
- }
- std::string hundreds(std::vector<int> src) {
- std::string hundred_string = "";
- if(src[0] == 0) {
- std::vector<int> dec_vec= {src[1],src[2]};
- std::string dec_str = decine(dec_vec);
- hundred_string.append(dec_str);
- return hundred_string;
- }
- else {
- hundred_string.append(first_twenty_vocabular[src[0]]);
- hundred_string.append("hundred ");
- std::vector<int> dec_vec= {src[1],src[2]};
- std::string dec_str = decine(dec_vec);
- hundred_string.append(dec_str);
- return hundred_string;
- }
- }
- std::string Stringer(std::vector<int> src) {
- std::string num_string = "";
- int len = src.size();
- if( src[0] < 0 ) {
- num_string.append("minus ");
- for (int i = 0; i < len; ++i) { src[i] = -i; }
- }
- if (len == 1) {
- std::string add = units(src);
- num_string.append(add);
- } else if (len == 2) {
- std::string add = decine(src);
- num_string.append(add);
- } else if (len == 3) {
- std::string add = hundreds(src);
- num_string.append(add);
- } else {
- return MagnitudeSplitter(src);
- }
- return num_string;
- }
- std::vector<int> VectorSplitter(std::vector<int> &V){
- std::vector<int> first_digits;
- int len = V.size();
- if (len%3 == 0) {
- for(int i = 0; i < 3; ++i) {
- first_digits.push_back(V[0]);
- FlipVector(V);
- V.pop_back();
- FlipVector(V);
- }
- } else {
- for( int i = 0; i < (len-(3*(len/3))); ++i) {
- first_digits.push_back(V[0]);
- FlipVector(V);
- V.pop_back();
- FlipVector(V);
- }
- }
- return first_digits;
- }
- std::string MagnitudeSplitter(std::vector<int> src) {
- int len = src.size();
- std::string tot_str = "";
- if (len == 3) {
- return Stringer(src);
- } else {
- std::vector<int> first_digits = VectorSplitter(src);
- int new_len = first_digits.size();
- std::string add = Stringer(first_digits);
- int sum_values = 0; // To know if there are only zeroes.
- for ( int i = 0; i < new_len; ++i) {
- sum_values += first_digits[i];
- }
- tot_str.append(add);
- if (sum_values) { tot_str.append(magnitude_vocabular[(len-1)/3]);
- }
- std::string return_str = Stringer(src);
- tot_str.append(return_str);
- }
- return tot_str;
- }
- int main() {
- std::cout << "insert your number: "; int x; std::cin >> x;
- std::vector<int> v_result = Splitter(x);
- FlipVector(v_result);
- PrintVector(v_result);
- std::cout << Stringer(v_result) << std::endl;
- }
- Output:
- Answer No:4.
- #include<iostream>
- using namespace std;
- class Area
- {private:
- int a,b;
- float c;
- public:
- void triangle()
- {cout <<"area of triangle is: " ;
- c=0.5*a*b;
- cout<<c <<endl;
- }
- void rectangle()
- {cout<<"area of rectangle is: "<<a*b<<endl;
- }
- Area(int x,int y)
- {
- a=x;
- b=y;
- }
- Area(int x)
- {
- a=x;
- }
- };
- int main()
- {Area obj(4,6);
- Area obj1=Area(2,3);
- Area obj2=8;
- obj.triangle();
- obj1.rectangle();
- return 0;
- }
- Output:
- Answer No:5.
- #include <iostream>
- class Person {
- protected:
- void breathe() {
- std::cout << "I'm in Engineering faculty." << std::endl;
- }
- };
- class Faculty : protected Person {
- protected:
- void breathe() {
- std::cout << "In ICT department." << std::endl;
- }
- };
- class Student : protected Person {
- protected:
- void crawl() {
- std::cout << "I'm Shanto." << std::endl;
- }
- };
- class Shanto : protected Faculty, protected Student {
- public:
- void breathe() {
- std::cout << "I'm Shanto." << std::endl;
- }
- void c() {
- std::cout << "My ID:IT-17027" << std::endl;
- }
- };
- int main() {
- Shanto shan;
- shan.breathe();
- shan.c();
- return 0;
- }
- Output:
- Answer No:6.
- ~Early binding
- #include <iostream>
- using namespace std;
- class Animals
- {
- public:
- void walk()
- {
- cout << "This is Early Binding" << endl;
- }};
- class Dogs : public Animals
- {
- public:
- void walk()
- {
- cout << "Dogs walk" << endl;
- }};
- int main()
- {
- Animals *a;
- Dogs d;
- a= &d;
- a -> walk(); // early binding
- return 0;
- }
- Output:
- ~~Late Binding
- #include <iostream>
- using namespace std;
- class Animals
- {
- public:
- virtual void sound()
- {
- cout << "This is Late binding" << endl;
- }
- };
- class cat : public Animals
- {
- public:
- void sound()
- {
- cout << "Mio mio mio miaaaao" << endl;
- }
- };
- int main()
- {
- Animals *a;
- cat d;
- a= &d;
- a -> sound();
- return 0;
- }
- Output:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement