`
oywl2008
  • 浏览: 1050556 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

CPlusProject Learning

    博客分类:
  • test
 
阅读更多

开发环境:Eclipse IDE for C/C++ Developers 

编译成功后,在Binaries ,run in local 后在控制台就可看到结果. 

 

 

https://www.w3schools.in/cplusplus-tutorial/inheritance/ 

 

 

//============================================================================
// Name        : CPlusProject.cpp
// Author      : William
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

class Calc
 {

public:
  int val2;
  Calc(int x)
  {
   val2=x;
 }
};

class stud
{
    public:
    char name[30],clas[10];
    int rol,age;
    string myname;

    void enter()
    {
//        cout<<"Enter Student Name: "; cin>>name;
//        cout<<"Enter Student Age: "; cin>>age;
//        cout<<"Enter Student Roll number: "; cin>>rol;
//        cout<<"Enter Student Class: "; cin>>clas;

//    	cout<<"Enter Student Name: "; cin>>myname;
    }

    void display()
    {
        cout<<"\n Age\tName\tR.No.\tClass";
        cout<<"\n"<<age<<"\t"<<name<<"\t"<<rol<<"\t"<<clas;
        cout<<"\n"<<myname;
    }
};


class studx {
protected:
    int roll, m1, m2;

public:
    void get()
    {
        cout << "Enter the Roll No.: "; cin >> roll;
        cout << "Enter the two highest marks: "; cin >> m1 >> m2;
    }
};
class extracurriculam {
protected:
    int xm;

public:
    void getsm()
    {
        cout << "\nEnter the mark for Extra Curriculam Activities: "; cin >> xm;
    }
};
class output : public studx, public extracurriculam {
    int tot, avg;

public:
    void display()
    {
        tot = (m1 + m2 + xm);
        avg = tot / 3;
        cout << "\n\n\tRoll No    : " << roll << "\n\tTotal      : " << tot;
        cout << "\n\tAverage    : " << avg;
    }
};


int main() {
//	std::cout<<"This is my first C++ Program.";
//	std::cout<<std::endl<<"and its very easy William";
	 const int SIDE = 60;
	  int area;
	  area = SIDE*SIDE;

	  std::cout<<"Area:\n" << area ;

	  cout<<"\n William Test C++";

	  int a = 15, b = 10;

	  if (b > a) {
		  cout << "\nb is greater" << endl;
	  }else{
		  cout << "\na is greater" << endl;
	  }

	  if(area > 3000){
		  cout << " 111" << endl;;
	  }else{
		  cout << " 222" << endl;;
	  }

	  int age[5]={2,25,30,32,35};
	  cout<<"\n " << age[1];
	  cout<<"\n sizeof: " << sizeof(age);
	  cout<<"\n sizeof: " << sizeof(age)/sizeof(age[0]);



	  for(int n=0;n<sizeof(age)/sizeof(age[0]);n++)
	  {
		  cout<<"\n " << age[n];
		  age[n] = age[n] + 100;
	  }

	  for(int n=0;n<sizeof(age)/sizeof(age[0]);n++)
	  {

	  }

	  for(int n=0;n<sizeof(age)/sizeof(age[0]);n++)
	  {
		  cout<<"\n " << age[n];
	  }
	  cout << endl;

	  int  n = 20, *ptr;  /* actual and pointer variable declaration */
	     ptr = &n;  /* store address of n in pointer variable*/
	     cout << "Address of n variable: " << &n << endl;

	      cout << "Address stored in pntr variable: " << ptr << endl;

	      cout << "Value of *pntr variable: " << *ptr << endl;

//	      char  *name;
//	      name = "Hello world 1";
//	      cout << "Value of *name variable: " << *name << endl;

	      string str;

	      str="Hello World 2";
	      cout << "Value of str variable: " << str << endl;


	       stud s;

	       Calc c1(10);
	       Calc c2(20);
	       Calc c3(30);

	        cout << c1.val2;
	         cout << c2.val2;
	         cout << c3.val2;
//	         s.enter();
//	         s.display();
//	         cin.get();//use this to wait for a keypress


	         output O;
	         O.get();
	         O.getsm();
	         O.display();

	return 0;
}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics