Tuesday, December 23, 2014

C++ using Excellant Program



Program 1

#include
#include
#include
using namespace std;
int main ()
{
  string mystr;
  float price=0;
  int quantity=0;
  cout << "Enter price: ";
  getline (cin,mystr);
  stringstream(mystr) >> price;
  cout << "Enter quantity: ";
  getline (cin,mystr);
  stringstream(mystr) >> quantity;
  cout << "Total price: " << price*quantity << endl;
  return 0;
}

Program 2
 
#include 
#include 
using namespace std;
int main ()
{
  string mystr;
  clrscr();
  cout << "What's your name? ";
  getline (cin, mystr);
  cout << "Hello " << mystr << ".\n";
  cout << "What is your favorite team? ";
  getline (cin, mystr);
  cout << "I like " << mystr << " too!\n";
  return 0;
}

Program 3
 
#include 
#include
using namespace std;
int main ()
{
  int i;
  cout << "Please enter an integer value: ";
  cin >> i;
  cout << "The value you entered is " << i;
  cout << " and its double is " << i*2 << ".\n";
  return 0;
}
 
Program 4
 
#include 
#include 
#include 
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 << "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";
}
 
Program 5
 
#include 
#include 
#include 
using namespace std;
struct movies_t 
{
  string title;
  int year;
} films [3];
void printmovie (movies_t movie);
int main ()
{
  string mystr;
  int n;
  for (n=0; n<3 n="" span="">
  {
    cout <<"Enter title: ";
    getline (cin,films[n].title);
    cout <<"Enter year: ";
    getline (cin,mystr);
    stringstream(mystr) >> films[n].year;
  }
  cout <<"\nYou have entered these movies:\n";
  for (n=0; n<3 n="" span="">
  printmovie (films[n]);
  return 0;
}
void printmovie (movies_t movie)
{
  cout <
  cout <<"(" << movie.year <<")\n";
}

No comments:

Post a Comment