LEC VI (CONT’D)
Character Sets
Character sets, also known as character encodings, are systems used to represent textual data in
computers and communication systems.
Definition:** A character set is a defined collection of characters, symbols, and glyphs, each
assigned a unique numeric code called a code point. These code points are typically represented
in binary form for processing by computers.
Types of character sets:
1. **ASCII (American Standard Code for Information Interchange):** ASCII is one of the
earliest character sets, encoding 128 characters using 7 bits. It includes uppercase and lowercase
letters, digits, punctuation marks, control characters, and special symbols.
2. **Extended ASCII:** Extended ASCII character sets use 8 bits to encode additional
characters beyond the original ASCII range. Various extended ASCII sets exist, including ISO-
8859 and Windows-1252, which include accented characters and symbols for different
languages.
3. **Unicode:** Unicode is a universal character encoding standard that aims to represent every
character from every language in the world, as well as symbols and special characters, using a
unique code point. It supports over 143,000 characters and is continually updated. Unicode can
be encoded using different transformation formats, such as UTF-8, UTF-16, and UTF-32, which
vary in the number of bytes used to represent each character.
4. **UTF-8 (Unicode Transformation Format - 8-bit):** UTF-8 is a variable-width encoding
that represents Unicode characters using 8-bit code units. It is backward compatible with ASCII
and widely used on the internet, as it efficiently represents ASCII characters while supporting
the full Unicode character set.
5. **UTF-16 (Unicode Transformation Format - 16-bit):** UTF-16 is a variable-width encoding
that represents Unicode characters using 16-bit code units. It can represent the entire Unicode
character set but may use more memory than UTF-8 for certain characters.
6. **UTF-32 (Unicode Transformation Format - 32-bit):** UTF-32 is a fixed-width encoding
that represents Unicode characters using 32-bit code units. It provides a straightforward
mapping between code points and code units but may be less space-efficient than UTF-8 and
UTF-16.
7. **Character Encoding Detection:** In some cases, it may be necessary to detect the character
encoding of a text file or data stream, especially when dealing with data from diverse sources.
Techniques such as byte order marks (BOM), heuristics, or explicit metadata can be used to
determine the character encoding.
Overall, character sets play a crucial role in enabling communication and data interchange
across different computer systems, programming languages, and human languages.
Understanding character sets and their encoding schemes is essential for ensuring proper
handling and display of textual data in software applications and communication protocols.
Reading and Writing to Files
Reading and writing to files is a fundamental operation in programming that allows data to be
stored persistently on disk and retrieved when needed. Here are some notes and examples on
reading and writing to files:
Reading from Files:
Example:
Reading from Files:
#include <iostream>
#include <fstream>
#include <string>
int main() {
// Open file in read mode
std::ifstream file("example.txt");
// Read data from the file
std::string data;
std::string line;
while (std::getline(file, line)) {
data += line + "\n";
// Close the file (automatically done when file goes out of scope)
file.close();
// Print the data
std::cout << data << std::endl;
return 0;
}
### Writing CSV Files:
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
int main() {
// Writing CSV file
std::ofstream csvFile("data.csv");
csvFile << "Name,Age\n";
csvFile << "John,30\n";
csvFile << "Alice,25\n";
csvFile.close();
// Reading CSV file
std::ifstream file("data.csv");
std::string line;
while (std::getline(file, line)) {
std::vector<std::string> row;
std::stringstream ss(line);
std::string cell;
while (std::getline(ss, cell, ',')) {
row.push_back(cell);
// Process row here...
}
file.close();
return 0;
HOMEWORK:
a. Research in C++, using the `ifstream` and `ofstream` classes to read from files using a loop to
read lines from the file until reaching the end
LEC VII
SOFTWARE ENGINEERING PRINCIPLES
These principles guide the development of robust, maintainable, and efficient software systems.
Overview:
1. **Better Requirement Analysis**:
- Understanding project requirements thoroughly is crucial. Clear vision and well-defined
requirements lead to successful software projects.
2. **Keep It Simple, Stupid (KISS) Principle**:
- Designs and implementations should be as simple as possible.
- Example: Avoid unnecessary complexity in code or architecture.
3. **Maintain the Vision**:
- Throughout the development process, maintain focus on the project's goals and vision.
- Consistently align development efforts with the original vision.
4. **Concepts and Principles Over Details**:
- While details matter, the underlying concepts and principles are critical.
- Understand the fundamental ideas behind software engineering practices.
5. **Relevance for CE/EE**:
- Software is pervasive in all aspects of our lives.
- Even for computer engineering (CE) and electrical engineering (EE) students, software concepts
are relevant.
- As CE/EE professionals, you'll build software systems, and understanding software engineering
principles is essential.
Process flows
Process flow in software engineering is crucial for building high-quality software.
Types of Software Process Flows:
1. **Waterfall Model**:
- A linear and sequential approach.
- Phases: Requirements gathering, design, implementation, testing, deployment, maintenance.
- Each phase depends on the completion of the previous one.
- **Advantages**: Clear milestones, well-defined
scope.
- **Disadvantages**: Less flexibility for changes, long
development cycles.
2. Agile Methodologies:
o Iterative and incremental approaches.
o Examples:
Scrum: Sprints with regular reviews and adaptability.
Kanban: Visualize work on a board, continuous delivery.
Extreme Programming (XP): Emphasizes collaboration, testing, and simplicity.
o Advantages: Flexibility, adaptability to changing requirements.
o Disadvantages: Requires active team involvement.
3. Spiral Model:
o Combines iterative development with risk assessment.
o Iteratively builds prototypes, evaluates risks, and refines the product.
o Advantages: Risk management, accommodates changes.
o Disadvantages: Complex, resource-intensive.
4. Rapid Application Development (RAD):
o Focuses on rapid prototyping and user feedback.
o Iterative cycles to quickly develop and refine software.
o Advantages: Speed, user involvement.
o Disadvantages: May sacrifice long-term stability.
5. Incremental Development:
o Divides software into smaller modules.
o Each module is developed and integrated incrementally.
o Advantages: Early functionality, easier testing.
o Disadvantages: Integration challenges.
6. Prototyping Model:
o Creates a working model to gather user feedback.
o Refines the prototype iteratively.
o Advantages: User involvement, early visualization.
o Disadvantages: May not address all requirements.
Steps involved in Process Flow
1. **Requirements Gathering and Analysis**:
- Understand client needs and gather detailed requirements.
- Analyze requirements to identify scope, constraints, and feasibility.
2. **System Design**:
- Create high-level and detailed designs.
- Define architecture, data models, and interfaces.
- Consider scalability, security, and performance.
3. **Implementation (Coding)**:
- Write code based on the design.
- Follow coding standards and best practices.
- Conduct unit testing.
4. **Testing and Quality Assurance**:
- Verify software functionality against requirements.
- Perform unit, integration, and system testing.
- Identify and fix defects.
5. **Deployment and Release**:
- Deploy the software to production environments.
- Prepare release notes and documentation.
- Monitor performance and address issues.
6. **Maintenance and Support**:
- Provide ongoing support to users.
- Address bug fixes, enhancements, and updates.
Advantages of Following a Software Process:
- **Predictability**: Processes provide a structured approach, making outcomes more
predictable.
- **Quality Assurance**: Rigorous testing ensures software quality.
- **Collaboration**: Teams work together efficiently.
- **Traceability**: Clear documentation helps trace decisions and changes.
## Disadvantages:
- **Complexity**: Large processes can be cumbersome.
- **Rigidity**: Strict adherence may hinder flexibility.
- **Overhead**: Processes require time and resources.
HOMEWORK:
a. What is the difference between Scrum and Kanban?
b. Can you give me an example of a Kanban board?
Best Practices in Software Development:
The best practices in software development can lead to efficient, maintainable, and high-quality
code
Including:
1. **Keep It Simple (KISS)**:
- Write code that is straightforward and easy to understand.
- Avoid unnecessary complexity or overengineering.
- Simplicity reduces bugs and improves maintainability.
2. **Version Control (Git)**:
- Use version control systems (e.g., Git) to track changes.
- Regularly commit code and create meaningful commit messages.
- Collaborate effectively with team members.
3. **Automate Repetitive Tasks**:
- Automate build processes, testing, and deployment.
- Continuous Integration (CI) tools can help automate workflows.
4. **Write Clean and Readable Code**:
- Follow consistent coding conventions (e.g., PEP 8 for Python).
- Use meaningful variable and function names.
- Add comments to explain complex logic.
5. **Test Thoroughly**:
- Write unit tests, integration tests, and end-to-end tests.
- Test edge cases and handle exceptions.
- Aim for high test coverage.
6. **Code Reviews**:
- Regularly review code with team members.
- Provide constructive feedback.
- Code reviews improve code quality and knowledge sharing.
7. **Refactor When Needed**:
- Refactor code to improve readability, performance, or maintainability.
- Eliminate code smells (e.g., duplicated code, long methods).
8. **Security Practices**:
- Sanitize user inputs to prevent security vulnerabilities (e.g., SQL injection, XSS).
- Keep dependencies updated to avoid known security issues.
9. **Documentation**:
- Document APIs, libraries, and codebase.
- Include README files with setup instructions.
- Good documentation aids collaboration and onboarding.
10. **Learn from Mistakes**:
- Embrace failures as learning opportunities.
- Conduct post-mortems after incidents.
- Continuously improve processes.
HOMEWORK:
a. What is the difference between unit tests and integration tests?
Design Principles in Software Engineering
These principles guide the development of robust, maintainable, and efficient software systems.
1. **Single Responsibility Principle (SRP)**:
- Each class/module should have only one reason to change.
- Avoid mixing multiple responsibilities within a single component.
- Example: A `FileReader` class should focus solely on file I/O operations without handling
other concerns.
2. **Open/Closed Principle (OCP)**:
- Software entities (classes, modules, functions) should be open for extension but closed for
modification.
- Extend functionality without altering existing code.
- Example: A `Shape` base class can be extended by adding new shape classes (e.g., `Circle`,
`Rectangle`) without modifying existing code.
3. **Liskov Substitution Principle (LSP)**:
- Objects of a derived class should be substitutable for objects of the base class without
affecting program correctness.
- Derived classes should adhere to the same behavior expected of the base class.
- Example: If we have a `Bird` base class, any derived bird (e.g., `Sparrow`, `Penguin`) should
satisfy bird-related behavior.
4. **Interface Segregation Principle (ISP)**:
- Break down large interfaces into smaller, more specific ones.
- Clients should not be forced to depend on methods they don't use.
- Example: Instead of a monolithic `Worker` interface, split it into separate interfaces for
specific roles (e.g., `Worker`, `Manager`, `Clerk`).
5. **Dependency Inversion Principle (DIP)**:
- Depend on abstractions (interfaces or abstract classes) rather than concrete implementations.
- High-level modules should not depend on low-level modules; both should depend on
abstractions.
- Example: Use an `ILogger` interface for logging, allowing flexibility in choosing specific
loggers (e.g., `FileLogger`, `ConsoleLogger`).
Remember, applying these principles leads to more maintainable, extensible, and robust software
designs.
HOMEWORK:
a. What is the difference between SRP and ISP?
b. What is the difference between LSP and DIP?
c. Write brief notes on the difference between C++ and Java?
// END OF LEC VII
// END OF LECS
// BEST OF LUCK WITH YOUR EXAMS