Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 1 (Suriya Narayanan) #2

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
Binary file added Suriya/.DS_Store
Binary file not shown.
Binary file added Suriya/Assignment1/.DS_Store
Binary file not shown.
34 changes: 34 additions & 0 deletions Suriya/Assignment1/Account.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//Exercise 3.12 - Class Source File
//ex3_12-Account.cpp

#include <iostream>
#include "Account.h"
using namespace std;

Account::Account(int number) {
setBalance(number);
}

void Account::setBalance(int number) {
if (number>=0)
balance = number;
if (number<0) {
balance = 0;
cout << "Error: Invalid value. Balance set to 0." << endl;
}
}

int Account::getBalance() {
return balance;
}

void Account::credit(int cred) {
setBalance(getBalance()+cred);
}

void Account::debit(int deb) {
if (deb<=getBalance())
setBalance(getBalance()-deb);
if (deb>getBalance())
cout<<"Debit amount exceeded account balance."<<endl;
}
14 changes: 14 additions & 0 deletions Suriya/Assignment1/Account.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//Exercise 3.12 - Header File
//ex3_12-Account.h

class Account{
public:
Account(int);
void setBalance(int);
int getBalance();
void credit(int);
void debit(int);

private:
int balance;
};
22 changes: 22 additions & 0 deletions Suriya/Assignment1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.23)
project(Assignment1)

set(CMAKE_CXX_STANDARD 14)

add_executable(ex2_19 ex2_19_main.cpp)
add_executable(ex2_24 ex2_24_main.cpp)
add_executable(ex2_25 ex2_25_main.cpp)
add_executable(ex2_28 ex2_28_main.cpp)
add_executable(ex3_11 ex3_11_main_GradeBook.cpp GradeBook.cpp GradeBook.h)
add_executable(ex3_12 ex3_12_main_Account.cpp Account.cpp Account.h)
add_executable(ex3_13 ex3_13_main_Invoice.cpp Invoice.cpp Invoice.h)
add_executable(ex3_14 ex3_14_main_Employee.cpp Employee.cpp Employee.h)
add_executable(ex3_15 ex3_15_main_Date.cpp Date.cpp Date.h)
add_executable(ex4_13 ex4_13_main.cpp)
add_executable(ex4_26 ex4_26_main.cpp)
add_executable(ex4_27 ex4_27_main.cpp)
add_executable(ex4_34 ex4_34_main.cpp)
add_executable(ex4_35d ex4_35_decrypt_main.cpp)
add_executable(ex4_35e ex4_35_encrypt_main.cpp)


33 changes: 33 additions & 0 deletions Suriya/Assignment1/Date.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//Exercise 3.15 - Class Source File
//ex3_15-Date.cpp

#include <iostream>
#include "Date.h"
using namespace std;

Date::Date(int month1, int day1, int year1) {
setDay(day1);
setMonth(month1);
setYear(year1);
}

void Date::setDay(int day1) {
day = day1;
}

void Date::setMonth(int month1) {
if (month1<1 || month1>12){
month = 1;
cout<<"Invalid month input. Month set to January"<<endl;
}
if (month1>=1 && month1<=12)
month = month1;
}

void Date::setYear(int year1) {
year = year1;
}

void Date::displayDate() {
cout<<"Recorded date is: "<<month<<"/"<<day<<"/"<<year<<endl;
}
17 changes: 17 additions & 0 deletions Suriya/Assignment1/Date.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//Exercise 3.15 - Header File
//ex3_15-Date.h

#include <string>
using namespace std;

class Date{
public:
Date(int, int, int);
void setDay(int);
void setMonth(int);
void setYear(int);
void displayDate();

private:
int day,month,year;
};
43 changes: 43 additions & 0 deletions Suriya/Assignment1/Employee.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//Exercise 3.14 - Class Source File
//ex3_14-Employee.cpp

#include<iostream>
#include<string>
#include "Employee.h"
using namespace std;

Employee::Employee(string f_name, string l_name, int pay){
setFirstName(f_name);
setLastName(l_name);
setSalary(pay);
}

void Employee::setFirstName(string f_name) {
fname = f_name;
}

void Employee::setLastName(string l_name) {
lname = l_name;
}

void Employee::setSalary(int pay) {
if (pay>=0)
salary = pay;
if (pay<0){
cout<<"Invalid value. Salary set to 0."<<endl;
salary = 0;
}
}

string Employee::getEmployeeName() {
return fname+" "+lname;
}

int Employee::getEmployeeSalary() {
return salary;
}

void Employee::displayAnnualSalary(){
cout<<getEmployeeName()<<"'s annual salary is: $ "<<getEmployeeSalary()*12<<endl;
}

20 changes: 20 additions & 0 deletions Suriya/Assignment1/Employee.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//Exercise 3.14 - Header File
//ex3_14-Employee.h

#include<string>
using namespace std;

class Employee{
public:
Employee(string, string, int);
void setFirstName(string);
void setLastName(string);
void setSalary(int);
string getEmployeeName();
int getEmployeeSalary();
void displayAnnualSalary();

private:
string fname, lname;
int salary;
};
34 changes: 34 additions & 0 deletions Suriya/Assignment1/GradeBook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//Exercise 3.11 - Class Source File
//ex3_11-GradeBook.cpp

#include <iostream>
#include <string>
#include "GradeBook.h"

using namespace std;

GradeBook::GradeBook( string name, string instr ) {
setCourseName( name );
setCourseInstr( instr );
}

void GradeBook::setCourseName( string name ) {
courseName = name;
}

void GradeBook::setCourseInstr( string instr) {
courseInstr = instr;
}

string GradeBook::getCourseName() {
return courseName;
}

string GradeBook::getCourseInstr() {
return courseInstr;
}

void GradeBook::displayMessage() {
cout << "Welcome to the grade book for\n" << getCourseName() << "!\n"
<< "This course is presented by: " << getCourseInstr() << ".\n" <<endl;
}
19 changes: 19 additions & 0 deletions Suriya/Assignment1/GradeBook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//Exercise 3.11 - Header File
//ex3_11-GradeBook.h

#include <string>
using namespace std;

class GradeBook
{
public:
GradeBook( string, string );
void setCourseName( string );
void setCourseInstr( string );
string getCourseName();
string getCourseInstr();
void displayMessage();

private:
string courseName,courseInstr;
};
60 changes: 60 additions & 0 deletions Suriya/Assignment1/Invoice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//Exercise 3.13 - Class Source File
//ex3_13-Invoice.cpp

#include <iostream>
#include <string>
#include "Invoice.h"
using namespace std;

Invoice::Invoice(string partnumb, string partdescript, int quan, int price1){
setPartNumber(partnumb);
setPartDescript(partdescript);
setQuant(quan);
setPrice(price1);
}

void Invoice::setPartNumber(string partnumb){
partNumber = partnumb;
}

void Invoice::setPartDescript(string partdescript){
partDescript = partdescript;
}

void Invoice::setQuant(int quan){
if (quan>=0)
quant = quan;
if (quan<0){
cout<<"Invalid input value. Quantity set to 0."<<endl;
quant = 0;
}
}

void Invoice::setPrice(int price1){
if (price1>=0)
price = price1;
if (price1<0){
cout<<"Invalid input value. Price set to 0."<<endl;
price = 0;
}
}

string Invoice::getPartNumber() {
return partNumber;
}

string Invoice::getPartDescript() {
return partDescript;
}

int Invoice::getQuant() {
return quant;
}

int Invoice::getPrice() {
return price;
}

int Invoice::getInvoiceAmount() {
return getQuant()*getPrice();
}
24 changes: 24 additions & 0 deletions Suriya/Assignment1/Invoice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//Exercise 3.13 - Header File
//ex3_12-Invoice.h

#include<string>
using namespace std;

class Invoice{
public:
Invoice(string,string,int,int);
void setPartNumber(string);
void setPartDescript(string);
void setQuant(int);
void setPrice(int);
string getPartNumber();
string getPartDescript();
int getQuant();
int getPrice();
int getInvoiceAmount();

private:
string partNumber, partDescript;
int quant, price;

};
41 changes: 41 additions & 0 deletions Suriya/Assignment1/ex2_19_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//Exercise 2.19
//ex2_19-main.cpp

#include <iostream>

using namespace std;

int main() {
int a,b,c;
cout << "Input three different integers: ";
cin >> a >> b >> c;
cout << "Sum is "<< a+b+c <<endl;
cout << "Average is "<< (a+b+c)/3 <<endl;
cout << "Product is "<< a*b*c <<endl;

if (a<=b){
if (a<=c)
cout<<"Smallest is "<<a<<endl;
if (a>c)
cout<<"Smallest is "<<c<<endl;
}
if (a>b){
if (b<=c)
cout<<"Smallest is "<<b<<endl;
if (b>c)
cout<<"Smallest is "<<c<<endl;
}

if (a>=b){
if (a>=c)
cout<<"Largest is "<<a<<endl;
if (a<c)
cout<<"Largest is "<<c<<endl;
}
if (a<b){
if (b>=c)
cout<<"Largest is "<<b<<endl;
if (b<c)
cout<<"Largest is "<<c<<endl;
}
}
16 changes: 16 additions & 0 deletions Suriya/Assignment1/ex2_24_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//Exercise 2.24
//ex2_24-main.cpp

#include <iostream>

using namespace std;

int main() {
int a;
cout << "Enter an integer: ";
cin >> a;
if (a%2 == 0)
cout << a <<" is even"<<endl;
if (a%2 != 0)
cout << a <<" is odd"<<endl;
}
Loading