Please stay healthy!

Remote Lectures

All Meetings

Schedule here:

Please join for the lectures!

Loraine will take attendance!

Email staff@cs410.net if you do not have a computer or no internet

High Quality Work!

Self-Motivation!

Despite the chaos:

2/7

2/21

2/28

3/27

5/22

Team Selection

Client Presentations

Project Proposal

Revised Project Proposal

Final Project Documentation

No class

No class

No class

Project Presentations

5/04

No class

Implementation / Testing / Deployment

57 Days

Revised Project Proposal

Due Today!

Can we start coding?

Most important

Revised Project Proposal

Will it still change?

Yes!

You will get feedback.

Revised Project Proposal

After feedback, copy it over..

Final Project Documentation

Due 5/22!

Keep updating it while you code..

Lecture 17

Hands-on Day! (C++ Functions and Classes)

Lecture 17

Hands-on Day! (C++ Functions and Classes)

Lecture 17

Hands-on Day! (C++ Functions and Classes)

#include <iostream>

int main()
{

  std::string temp;
  
  std::cout << "Please enter a temperature in F. ";
  
  std::cin >> temp;
  
  float convertedTemp = std::stof(temp) - 32 / 1.8;
  
  std::cout << "Converted to Celsius, this temperature is "
  	<< convertedTemp << "!\n";
  
}

Lecture 17

Hands-on Day! (C++ Functions and Classes)

#include <iostream>

int main()
{

  std::string temp;
  
  std::cout << "Please enter a temperature in F. ";
  
  std::cin >> temp;
  
  float convertedTemp = ( std::stof(temp) - 32 ) / 1.8;
  
  std::cout << "Converted to Celsius, this temperature is "
  	<< convertedTemp << "!\n";
  
}

Lecture 17

Hands-on Day! (C++ Functions and Classes)

#include <iostream>

int main()
{

  float temp;
  
  std::cout << "Please enter a temperature in F. ";
  
  std::cin >> temp;
  
  float convertedTemp = ( temp - 32 ) / 1.8;
  
  std::cout << "Converted to Celsius, this temperature is "
  	<< convertedTemp << "!\n";
  
}

Hidden Casting!

Lecture 17

Hands-on Day! (C++ Functions and Classes)

// part 2
class Converter {
    
    public:
        float fromFtoC(float);
    
};

float Converter::fromFtoC(float temp) {
    
  return ((temp-32)/1.8);
  
};
  //... in main
  Converter c;
  
  float convertedTemp = c.fromFtC(temp);
  //...

Lecture 17

Hands-on Day! (C++ Functions and Classes)

// part 2
class Converter {
    
    public:
        float fromFtoC(float);
    
};

float Converter::fromFtoC(float temp) {
    
  return ((temp-32)/1.8);
  
};
  //... in main
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...

Pointer to the instance!

Lecture 17

Hands-on Day! (C++ Functions and Classes)

  //... in main
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...

Pointer to the instance!

  //... in main
  Converter *c;
  
  float convertedTemp = c->fromFtoC(temp);
  //...

Wild pointer!

std::unique_ptr<Converter> c(new Converter());    

c->fromFtoC(temp);

One way to avoid wild pointers...

Templates.. (next week)

Lecture 17

Hands-on Day! (C++ Functions and Classes)

// part 2
class Converter {
    
    public:
        float fromFtoC(float);
    
};

float Converter::fromFtoC(float temp) {
    
  return ((temp-32)/1.8);
  
};
  //... in main
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...
  //... somewhere else in the code
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...
  //... somewhere else again
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...

3 instances!

Lecture 17

Hands-on Day! (C++ Functions and Classes)

  //... Everywhere!
  SingletonConverter *c = SingletonConverter::getInstance()
  float convertedTemp = c->fromFtC(temp);
  //...
  //... in main
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...
  //... somewhere else in the code
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...
  //... somewhere else again
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...

Always use the same instance!

Lecture 17

Hands-on Day! (C++ Functions and Classes)

  //... in main
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...
  //... somewhere else in the code
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...
  //... somewhere else again
  Converter *c = new Converter;
  
  float convertedTemp = c->fromFtoC(temp);
  //...

3x Converter

  //... in main
  SingletonConverter *c = SingletonConverter::getInstance()
  float convertedTemp = c->fromFtC(temp);
  //...
  //... somewhere else in the code
  SingletonConverter *c = SingletonConverter::getInstance()
  float convertedTemp = c->fromFtC(temp);
  //...
  //... somewhere else again
  SingletonConverter *c = SingletonConverter::getInstance()
  float convertedTemp = c->fromFtC(temp);
  //...

1x Converter

Lecture 17

Hands-on Day! (C++ Functions and Classes)

// part 3
class SingletonConverter
{
   public:
       static SingletonConverter* getInstance( ) {
       
            return instance;
       
       };
       ~SingletonConverter( );
        float fromFtoC(float temp) {
            return ((temp-32)/1.8);
        };
   private:
       SingletonConverter( );
       static SingletonConverter* instance;
};
  //... in main
  SingletonConverter *c = SingletonConverter::getInstance()
  float convertedTemp = c->fromFtC(temp);
  //...

Lecture 17

Hands-on Day! (C++ Functions and Classes)

// part 3
class SingletonConverter
{
   public:
       static SingletonConverter* getInstance( ) {
       
       	    static SingletonConverter* instance;
            return instance;
       
       };
       ~SingletonConverter( );
        float fromFtoC(float temp) {
            return ((temp-32)/1.8);
        };
   private:
       SingletonConverter( );
};
  //... in main
  SingletonConverter *c = SingletonConverter::getInstance()
  float convertedTemp = c->fromFtC(temp);
  //...

Lazy Loading!

Arrays and

Vectors

Variable

Array

int carton[10];
int carton[10] = { };
int carton[10] = { 1, 3, 7 };

Array is full..

Larger Array...

It will be full eventually...

What about a dynamic container?

Vector

Let's try it!

#include <iostream>

class SingletonConverter
{
   public:
       static SingletonConverter* getInstance( ) {
       
            return instance;
       
       };
       ~SingletonConverter( );
        float fromFtoC(float temp) {
            return ((temp-32)/1.8);
        };
   private:
       SingletonConverter( );
       static SingletonConverter* instance;
};

int main()
{

  std::string temp;
  std::cout << "Please enter a temperature. ";
  std::cin >> temp;
  
  std::cout << "Converted to Celsius, this temperature is " << SingletonConverter::getInstance()->fromFtoC(std::stof(temp)) << "!\n";
  
}

CS410 Lecture 20

By Daniel Haehn

CS410 Lecture 20

Slides for CS410 Software Engineering at UMass Boston. See https://cs410.net!

  • 377