ADVERTISEMENT

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.
Showing posts with label CSE1002:PP8. Show all posts
Showing posts with label CSE1002:PP8. Show all posts

Friday, 29 April 2016

CSE1002:PP8:Car Mileage Calculation Problem

A workshop has a variety of cars. The details of the car such as car number, miles driven, and gallons of gas used in each car is stored in a file.
Car Number          Miles Driven         Gallons used
      54            250            19
      62            525            38
      71            123            6
      85            1,322            86
      97            235            14
Write a  C++ program that reads the data in the file created and displays the car number, miles driven, gallons used, and the miles per gallon for each car.

PSEUDOCODE:
START
READ s;
READ FILE with name s in f
while(!f.eof())
f>>car>>mile>>gal;
SET avg=mile/gal;
SET total+=mile;
SET totalg+=gal;
SET tavg+=avg;
PRINT car,mile,gal,avg
end while
PRINT total,totalg,tavg,tavg/n;
STOP
CODE:
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
main()
{int car,n=0;
char s[100];
cin>>s;
float mile,gal,total=0,totalg=0,avg,tavg=0;
fstream f;
f.open(s,ios::in);
while(!f.eof())
{
f>>car>>mile>>gal;
avg=mile/gal;
total+=mile;
totalg+=gal;
tavg+=avg;
cout<<fixed<<setprecision(2)<<car<<" "<<mile<<" "<<gal<<" "<<avg<<endl;
n++;
}
cout<<fixed<<setprecision(2)<<total<<endl<<totalg<<endl<<tavg<<endl<<tavg/n;
}

CSE1002:PP8:Code Detection Problem

Code Detection Problem 

 For security reasons, messages are transmitted as a secret code over a transmission channel. It is usually sent as a sequence of bits, that is, 0s and 1s. Due to noise in the transmission channel, the transmitted message may become corrupted. That is, the message received at the destination may not be the same as the message transmitted. There are several techniques to check the validity of the transmitted message at the destination. One such technique is to transmit the same message twice. At the destination, both copies of the message are compared. Given a file "data.txt" with the messages that is transmitted, write a C++ program to check whether the message received at the destination is error-free. For simplicity, assume that the secret code representing the message is a sequence of digits(0 to 9) and the maximum length of the message is 250 digits. Each original message is followed by a copy message and first number in both the messages indcates the length of the message. Each character in the message is separated by a space. For example, 7 9 2 7 8 3 5 6 7 9 2 7 8 3 5 6 means that the original message is of length 7 and it is 9 2 7 8 3 5 6 and copy message is also of length 7 and it is 9 2 7 8 3 5 6. If orginal and copy message is same then print Message transmitted is ok. Print Message transmitted is not OK when th length of the original or copy message is greater than 250 or when the original message is not same as copy message.

PSEUDOCODE:

START
READ name
OPEN FILE NAME IN l
while(!I.eof())
int a=0,b,c=0,d;
I>>n;
for i->0 to n
 I>>b;
 a=10*a+b;
end for
I>>m;
for i->0 to n
 I>>d;
 c=10*c+d;
end for
if(a==c)
 PRINT OK
else
 PRINT NOTOK
end if
STOP

CODE:

#include<iostream>
#include<string>
#include<fstream>
using namespace std;
main()
{
fstream f;
char name[20];
cin>>name;
f.open(name,ios::in);
int n,m;
while(!f.eof())
{int a=0,b,c=0,d;
f>>n;
for(int i=0;i<n;i++)
 {f>>b;
 a=10*a+b;
 }
f>>m;
for(int i=0;i<m;i++)
 {
 f>>d;
 c=10*c+d;
 }
if(a==c)
 cout<<"Message transmitted ok"<<endl;
else
 cout<<"Message transmitted is not ok"<<endl;

}
}

CSE1002:PP8:Special Pay Increase Problem

CSE1002 Special Pay Increase Problem 

Employees in a company are up for a special pay increase. Given a file, with each line consisting of an employee's last name, first name, current salary, and percent pay increase, write a C++ program to compute the revised pay of each employee.
            Miller Andrew     65875.87  5
            Green Sheila     75892.56 6
            Sethi Amit        74900.50 6.1.
For example, the pay increase for Andrew is 5%.
UML:
 
CODE:
void employee::get(ifstream &f)
{
f>>firstName;
f>>lastName;
f>>salary;
f>>inc;
}
void employee::update_Sal()
{
updated_Salary=salary+salary*inc/100;
}
void employee::print()
{
cout<<firstName<<endl<<lastName<<endl<<fixed<<setprecision(2)<<updated_Salary<<endl;
}
int main()
{
char s[100];
ifstream f;
cin>>s;
f.open(s,ios::in);
employee e[100];
int i=0;
while(!f.eof())
{
e[i].get(f);
e[i].update_Sal();
e[i].print();
i++;
}
return 0;
}

CSE1002:PP8:SORTING DATA IN FILE

PSUDOCODE:

START
READ s;
OPEN FILE s
SET c=0
SET vector<int> v;
while(!f.eof())
f>>c;
v.push_back(c);
end while
sort vector v
print vector v
end for
STOP

CODE:
#include<fstream>
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
ifstream f;
char s[100];
cin>>s;
char d;
f.open(s);
int c=0;
int count=0;
vector<int> v;
while(!f.eof())
{
f>>c;
v.push_back(c);
}
sort(v.begin(),v.end());
for(c=0;c<v.size();c++)
{
cout<<v[c]<<endl;
}
return 0;
}

Thursday, 28 April 2016

CSE1002:PP8:Number of words

PSUDOCODE:

START
READ s;
SET char d;
OPEN FILE "tweets.txt" in f
SET int c=0;
SET int count=0;
while(!f.eof())
f.get(d);
if(d==s[c])
c++;
else
c=0;
end if
if(c==strlen(s))
count++;
c=0;
end if
end while
print count
STOP

CODE:
 #include<fstream>
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
fstream f;
char s[100];
cin>>s;
char d;
f.open("tweets.txt",ios::in);
int c=0;
int count=0;
while(!f.eof())
{
f.get(d);
if(d==s[c])
{
c++;
}
else
{c=0;}
if(c==strlen(s))
{
count++;
c=0;
}
}
cout<<count;



return 0;
}

CSE1002:BONUS: FIND A ROUTE

FIND A ROUTE
Rahul is fond of travelling and he visits cities and towns in the country whenever possible. All cities in the country are not connected to each other. Given the details of the cities that are connected to each city, source city from where he begins the travel and the destination city of the travel, design an algorithm and write a C++ code to list down the cities in the travel. Rahul must not visit a city more than once. When the destination city name is in the connected cities of the current city, chose it and complete the route. When there is more than one city from the current city, he sorts the city names and include the first minimum city name that is not yet visited. For example, if the connection between the cities are given as follows, source city as A and destination city as F the list of cities in the travel are A, B, D and F.

UML:


CODE:
void travel::get()
{
cin>>num_Of_Cities;
for(int i=0;i<num_Of_Cities;i++)
 {int c;
 string cur;
 cin>>cur>>c;
 for(int j=0;j<c;j++)
 {string temp;
 cin>>temp;
 city_Connection[cur].push_back(temp);
 }
 }
cin>>source>>destn;
}
void travel::find_Route()
{
route.push_back(source);
while(route.back()!=destn)
{
 bool f=true;
 vector<string> s=city_Connection[route.back()];
 sort(s.begin(),s.end());
 if(find(s.begin(),s.end(),destn)!=s.end())
 {route.push_back(destn);break;}
 for(int i=0;i<s.size();i++)
 if (find(route.begin(),route.end(),s[i])==route.end())
 {route.push_back(s[i]);f=false;break;}
}
}
void travel::print_Route()
{
for(int i=0;i<route.size();i++)
 cout<<route[i]<<endl;
}