[go: up one dir, main page]

0% found this document useful (0 votes)
2 views8 pages

Include

The document contains multiple C++ programs that demonstrate the use of structures and classes to manage various data types, including Points, Rectangles, Players, Movies, Books, Cars, and Sports Teams. Each program prompts the user for input and displays the corresponding details. The examples illustrate basic input/output operations and the use of member functions in classes.

Uploaded by

radammm5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Include

The document contains multiple C++ programs that demonstrate the use of structures and classes to manage various data types, including Points, Rectangles, Players, Movies, Books, Cars, and Sports Teams. Each program prompts the user for input and displays the corresponding details. The examples illustrate basic input/output operations and the use of member functions in classes.

Uploaded by

radammm5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

#include <iostream>

using namespace std;

struct Point {

int x;

int y;

};

int main() {

Point p;

cout << "Enter x-coordinate: ";

cin >> p.x;

cout << "Enter y-coordinate: ";

cin >> p.y;

cout << "\nPoint coordinates: (" << p.x << ", " << p.y << ")\n";

return 0;

Enter x-coordinate: 5

Enter y-coordinate:
10

Point coordinates: (5,


10)
#include <iostream>

using namespace std;

struct Rectangle {

int length;

int width;

};

int main() {

Rectangle rect;

cout << "Enter length of the rectangle: ";

cin >> rect.length;

cout << "Enter width of the rectangle: ";

cin >> rect.width;

int area = rect.length * rect.width;

cout << "\nArea of the rectangle: " << area << endl;

return 0;

Enter length of the


rectangle: 8

Enter width of the


rectangle: 5

Area of the
rectangle: 40
#include <iostream>
#include <string>
using namespace std;
struct Player {
string name;
string sport;
int age;
};
int main() {

Player player;
cout << "Enter player name: ";
cout << "Enter sport: ";
cout << "Enter player age: ";
cin >> player.age;
cout << "\nPlayer Details:\n";
cout << "Name: " << player.name << endl;
cout << "Sport: " << player.sport << endl;
cout << "Age: " << player.age << endl;
return 0;
}
Enter player name:
Lionel Messi
Enter sport: Football
Enter player age: 36
Player Details:
Name: Lionel Messi
Sport: Football
Age: 36

#include <iostream>
#include <string>
using namespace std;
struct Movie {
string title;
string director;
int releaseYear;
};
int main() {
Movie movie;
cout << "Enter movie title: ";
cout << "Enter movie director: ";
cout << "Enter movie release year: ";
cin >> movie.releaseYear;
cout << "\nMovie Details:\n";
cout << "Title: " << movie.title << endl;
cout << "Director: " << movie.director << endl;
cout << "Release Year: " << movie.releaseYear << endl;
return 0;
}

Enter movie title:


Inception
Enter movie director:
Christopher Nolan
Enter movie release
year: 2010

Movie Details:
Title: Inception
Director: Christopher
Nolan
Release Year: 2010

#include <iostream>
#include <string>
using namespace std;
class Book {
private:
string title;
string author;
int pages;
public:
void inputDetails() {
cout << "Enter book title: ";
getline(cin, title);
cout << "Enter author name: ";
getline(cin, author);
cout << "Enter number of pages: ";
cin >> pages;
}
void displayDetails() const {
cout << "\nBook Details:\n";
cout << "Title: " << title << endl;
cout << "Author: " << author << endl;
cout << "Pages: " << pages << endl;
}
};
int main() {
Book myBook;
myBook.inputDetails();
myBook.displayDetails();
return 0;
}
Enter book title: The
Alchemist
Enter author name:
Paulo Coelho
Enter number of
pages: 208
Book Details:
Title: The Alchemist
Author: Paulo Coelho #include <iostream>
Pages: 208 #include <string>
using namespace std;
class Car {
private:
string brand;
string model;
int year;
public:
void inputDetails() {
cout << "Enter car brand: ";
getline(cin, brand);
cout << "Enter car model: ";
getline(cin, model);
cout << "Enter manufacturing year: ";
cin >> year;
}
void displayDetails() const {
cout << "\nCar Details:\n";
cout << "Brand: " << brand << endl;
cout << "Model: " << model << endl;
cout << "Year: " << year << endl;
}
};
int main() {
Car myCar;
myCar.inputDetails();
myCar.displayDetails();
return 0;
}
AoA, [7/12/2024
12:46 ‫]ص‬
Enter car brand:
Tesla
Enter car model:
Model S
Enter manufacturing
year: 2022
Car Details: #include <iostream>
Brand: Tesla #include <string>
using Model: Model S namespace std;
class Year: 2022 SportsTeam {
private:
string teamName;
string sport;
int championshipsWon;
public:
void inputDetails() {
cout << "Enter team name: ";
getline(cin, teamName);
cout << "Enter sport: ";
getline(cin, sport);
cout << "Enter number of championships won: ";
cin >> championshipsWon;
}
void displayDetails() const {
cout << "\nSports Team Details:\n";
cout << "Team Name: " << teamName << endl;
cout << "Sport: " << sport << endl;
cout << "Championships Won: " << championshipsWon << endl;
}
};
int main() {
SportsTeam team;
team.inputDetails();
team.displayDetails();
return 0;
}
Enter team name:
Golden State
Warriors
Enter sport:
Basketball
Enter number of
championships won:
7 #include <iostream>
Sports Team Details: #include <string>
Team Name: Golden using namespace std;
State Warriors class Movie {
Sport: Basketball private:
Championships Won: string title;
7 string director;
float rating;
public:
void inputDetails() {
cout << "Enter movie title: ";
getline(cin, title);
cout << "Enter director name: ";
getline(cin, director);
cout << "Enter movie rating (out of 10): ";
cin >> rating;
}
void displayDetails() const {
cout << "\nMovie Details:\n";
cout << "Title: " << title << endl;
cout << "Director: " << director << endl;
cout << "Rating: " << rating << "/10" << endl;
}
};
int main() {
Movie myMovie;
myMovie.inputDetails();
myMovie.displayDetails();
return 0;
}
Enter movie title:
Interstellar
Enter director name:
Christopher Nolan
Enter movie rating
(out of 10): 9.0
Movie Details:
Title: Interstellar
Director: Christopher
Nolan
Rating: 9.0/10

You might also like