Posts

Simple class example of c++ for beginners

Image
This class maintain a library card catalog entry.Have the class store a book's title,author,and the number  of copies available. #include<iostream> using namespace std; class card {     private:             char booksTitle[50],author[50];             int av_copies;     public:         set_a()         {             cout<<"Enter the Books Title:" << endl;             cin>> booksTitle;             cout<<"Author:" << endl;             cin>> author;             cout<<"Available copies:" << endl;             cin>> av_copies;         }         show()       ...

C++ basic input output

Image
1.Star pattern with simple input output  #include<iostream> using namespace std; int main() {   cout<<"*\n"<<"**\n"<<"***\n"<<"****\n"<<"*****\n"<<endl;   return 0; } Output: 2.Character input output #include <iostream> using namespace std; int main() {     char name[50];     cout<<"Enter name:";     cin>>name;     cout<<"Hello "<<name<<"!";     return 0; } Output: 3.Simple input output #include <iostream> using namespace std; int main() {     int x;     int y;     float z;     x=10;     y=15;     z=12.6;     cout<<x<<" "<<y<<" "<<z<<endl;     return 0; } Output: 4...

A simple class:This example contains a class and two objects of that class.The program demonstrates the syntax and general features of classes in c++.

#include<iostream> using namespace std; class myclass {     private:        int a;     public:         void set_a()          {             cout<<"Enter the value:" <<endl;             cin>>a;         }         void get_a()         {             cout<<"Your value is:" <<a <<endl;         } }; int main() {     myclass a1,a2;     a1.set_a();     a1.get_a();     a2.set_a();     a2.get_a(); return 0; }