latest Post

Program struck dengan C++

Berikut contoh program struck dengan menggunakan Dev-C++

#include <string.h>
#include <iostream>
using namespace std;
struct Books
{
 char title [50];
 char author [50];
 char subject [100];
 int book_id;
};

int main()
{
struct Books Book1;
struct Books Book2;

strcpy (Book1.title, "C Programming");
strcpy (Book1.author, "Nuha Ali");
strcpy (Book1.subject, "C Programming Tutorial");
Book1.book_id = 6495407;

strcpy (Book2.title, "Telecom Billing");
strcpy (Book2.author, "Zara Ali");
strcpy (Book2.subject, "Telecom Billing Tutorial");
Book2.book_id = 6495700;

cout<<"Book1 title   : "<<Book1.title<<endl;
cout<<"Book1 author  : "<< Book1.author<<endl;
cout<<"Book1 subject : "<< Book1.subject<<endl;
cout<<"Book1 book_id : "<< Book1.book_id<<endl;

cout<<"Book2 title   : "<< Book2.title<<endl;
cout<<"Book2 author  : "<< Book2.author<<endl;
cout<<"Book2 subject : "<< Book2.subject<<endl;
cout<<"Book2 book_id : "<< Book2.book_id<<endl;

return 0;
}



#include <string.h>
#include <iostream>
#include <sstream>
using namespace std;

struct movies_t {
 string title;
 int year;

}mine,yours;

void printmovie(movies_t movie);

int main()
{
 string mystr;
 mine.title="2001 A space odyssey";
 mine.year=1968;
 
 cout<<"Enter Title : ";
 getline(cin,yours.title);
 cout<<"Enter Year  : ";
 getline(cin,mystr);
 stringstream(mystr)>>yours.year;
 
 cout<<endl;
 cout<<"My favorite movie is : \n";
 printmovie (mine);
 cout<<"And yours is :\n";
 printmovie(yours);
 return 0;

}
void printmovie(movies_t movie)
{
 cout<<movie.title;
 cout<<"(" <<movie.year<<")\n";
}



#include <iostream>

using namespace std;

class Box
{
 public:
  double length;
  double breadth;
  double height;
  
};

int main ()
{
 Box Box1;
 Box Box2;
 double volume = 0.0;
 
 Box1.height = 5.0;
 Box1.length = 6.0;
 Box1.breadth= 7.0;
 
 Box2.height = 10.0;
 Box2.length = 12.0;
 Box2.breadth= 13.0;
 volume = Box1.height*Box1.length*Box1.breadth;
 cout<<"Volume of Box1 : "<<volume<<endl;
 volume = Box2.height*Box2.length*Box2.breadth;
 cout<<"Volume of Box2 : "<<volume<<endl;
 return 0;
}

About Unknown

Unknown
Recommended Posts × +

0 comments:

Post a Comment