Project design
- C course
- Beginner
- Lesson 112/116
- 6 min
Design the skeleton of the beginner final mini app.
Project: Book catalog
In this five-lesson beginner final you will build a book catalog app that combines everything you have learned. In the first lesson you define a struct Book and print a book.
In later lessons you will add layers for an array of books, a print function, dynamic memory and a final combination on top of this base. Each lesson adds one piece with a code step; the starting code includes the previous lesson's solution. This shows how a real app grows.
Book struct design
A struct Book carries a book's title (title) and year (year). The title is a 32-character string, the year is an integer.
struct Book {
char title[32];
int year;
};This struct is the foundation of the project. In later lessons you will create variables, arrays and dynamic memory from this struct. Members are accessed with the . operator: b.title, b.year. Each book carries these two pieces of information together.
Practice Define the Book struct and print
Define struct Book with char title[32] and int year members. In main create a Book with {"War and Peace", 1869} and print title and year with printf.
Starter code
#include <stdio.h>
// Define struct Book with title and year members
int main(void) {
// Create a Book and print it with printf
return 0;
}Sample solution
struct Book { char title[32]; int year; };
struct Book b = {"War and Peace", 1869};
printf("%s %d\n", b.title, b.year);Expected output
War and Peace 1869
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What will we manage in this project?
- Invoices
- Customers
- Orders
- Books Correct answer
Explanation: the project is a book catalog app; you define and print books.
2 Define the year member
struct Book {
char title[32];
int ____;
};
struct Book {
char title[32];
int year;
};
Explanation: year is an int member; it holds the book's publication year.
3 Match each piece to its purpose
| Term | Meaning |
|---|---|
title |
Book title |
year |
Publication year |
struct Book |
Struct definition |
.title |
Member access |