14.data structure - bookshelf
23 May 2020 | STL Programming Practice_1
Part 1
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
/*
struct [structure tag]
{
member definition;
member definition;
...
member definition;
}[one or more structure variables](optional);
*/
int main()
{
return 0;
}
Part 2
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
/*
struct [structure tag]
{
member definition;
member definition;
...
member definition;
}[one or more structure variables](optional);
*/
struct Books
{
char Title[20];
char Author[20];
int ID;
float price;
}book1;
// book1 is now a variable of Books data type(Global variable(declare on top on the program)
int main()
{
// Local variable(declared inside a block of code)
book1.ID = 10;
book1.price = 13.67;
strcpy(book1.Title, "Data structure");
strcpy(book1.Author, "Mark");
cout<<"Book1 title is: " <<book1.Title<<"\n";
cout<<"Book1 Author is: " <<book1.Author<<"\n";
cout<<"ID : " <<book1.ID<<" and the price : "<<book1.price<<"\n";
Books book2;
book2.ID = 100;
book2.price = 16.4;
cout<<"ID : " <<book2.ID<<" and the price : "<<book2.price<<"\n";
return 0;
}
Part3
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
/*
struct [structure tag]
{
member definition;
member definition;
...
member definition;
}[one or more structure variables](optional);
*/
struct Books
{
char Title[20];
char Author[20];
int ID;
float price;
}book1;
// book1 is now a variable of Books data type(Global variable(declare on top on the program)
void printingBooks (Books variableBook)
{
cout<<"Book1 title is: " <<variableBook.Title<<"\n";
cout<<"Book1 Author is: " <<variableBook.Author<<"\n";
cout<<"ID : " <<variableBook.ID<<" and the price : "<<variableBook.price<<"\n";
}
int main()
{
// Local variable(declared inside a block of code)
book1.ID = 10;
book1.price = 13.67;
strcpy(book1.Title, "Data structure");
strcpy(book1.Author, "Mark");
printingBooks(book1);
return 0;
}
Part 1
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
/*
struct [structure tag]
{
member definition;
member definition;
...
member definition;
}[one or more structure variables](optional);
*/
int main()
{
return 0;
}
Part 2
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
/*
struct [structure tag]
{
member definition;
member definition;
...
member definition;
}[one or more structure variables](optional);
*/
struct Books
{
char Title[20];
char Author[20];
int ID;
float price;
}book1;
// book1 is now a variable of Books data type(Global variable(declare on top on the program)
int main()
{
// Local variable(declared inside a block of code)
book1.ID = 10;
book1.price = 13.67;
strcpy(book1.Title, "Data structure");
strcpy(book1.Author, "Mark");
cout<<"Book1 title is: " <<book1.Title<<"\n";
cout<<"Book1 Author is: " <<book1.Author<<"\n";
cout<<"ID : " <<book1.ID<<" and the price : "<<book1.price<<"\n";
Books book2;
book2.ID = 100;
book2.price = 16.4;
cout<<"ID : " <<book2.ID<<" and the price : "<<book2.price<<"\n";
return 0;
}
Part3
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
/*
struct [structure tag]
{
member definition;
member definition;
...
member definition;
}[one or more structure variables](optional);
*/
struct Books
{
char Title[20];
char Author[20];
int ID;
float price;
}book1;
// book1 is now a variable of Books data type(Global variable(declare on top on the program)
void printingBooks (Books variableBook)
{
cout<<"Book1 title is: " <<variableBook.Title<<"\n";
cout<<"Book1 Author is: " <<variableBook.Author<<"\n";
cout<<"ID : " <<variableBook.ID<<" and the price : "<<variableBook.price<<"\n";
}
int main()
{
// Local variable(declared inside a block of code)
book1.ID = 10;
book1.price = 13.67;
strcpy(book1.Title, "Data structure");
strcpy(book1.Author, "Mark");
printingBooks(book1);
return 0;
}
Comments