IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> EE308_LAB2 -> 正文阅读

[Python知识库]EE308_LAB2

The Link Your Classhttps://bbs.csdn.net/forums/MUEE308FZ?category=0
The Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/600798588
The Aim of This Assignment1. To achieve a program function 2. Extract keywords of different levels from the C++ code files that are read in 3. learn the use of github
MU STU ID and FZU STU ID19103921_831902217

?Content

🎪The Links

https://github.com/yyx0115/EE308_LAB2/tree/main

📝PSP FORM

Personal Software Process stageEstimated Time(min)Actual Time(min)
Planning
Estimate3030
Development
Analysis100120
Design Spec60100
Design Review1515
Coding Standard3030
Design180200
Coding12001600
Code Review6060
Test100100
Reporting
Test Report3030
Size Measurement1515
Postmortem & Process Improvement Plan6060
Sum of Time18802360

🌋Description of problem-solving ideas

  1. Choose Language
  • c++/c
  • Python
  • java
  1. Review the knowledge of C/C++
    we need to know the keywords:
    在这里插入图片描述

After last semester’s study, I acquired some knowledge about Java, C ++/ C. It’s a pity that I didn’t learn Python yet. After a summer vacation of “indulgence”, before starting this assignment, I need to review the “if-else” knowledge to wake up my memory

  1. rough thinking
  • The file is read in the specified address

  • Create a user input class

  • a search class to find the keywords

  • a class to calculate the number of keywords and the times of switches and cases

  • use pointer function probably

  • the number of if-else and if else if else

📜The Chart of the Key Functions

if not
if it is
find the case
find the last word is 'if'
find the last two words are 'if else'
get the road of file
Traverse every word in the file
judge whether it's keyword
search next word
key++
total num
if find a switch
switch_num++
switch num
switch_case_num++
case num
if find an 'else'
if_else_num++
if_else num
ifelse_ifelse_num++
if_elseif_else num

💫Code Description

  1. create a file named “in.txt” include?:
#include <stdio.h>
int main(){
    int i=1;
    double j=0;
    long f;
    switch(i){
        case 0:
            break;
        case 1:
            break;
        case 2:
            break;
        default:
            break;
    }
    switch(i){
        case 0:
            break;
        case 1:
            break;
        default:
            break;
    }
    if(i<0){
        if(i<-1){}
        else{}
    }
    else if(i>0){
        if (i>2){}
        else if (i==2) {}
        else if (i>1) {}
        else {}
    }
    else{
        if(j!=0){}
        else{}
    }
    return 0;
}
  1. The input?:

    #include<bits/stdc++.h>
    using namespace std;
    map<string,int> mp;
    string words[32]={"auto","case","char","const","do",
    		   "double","enum","extern","float","goto",
    		   "int","long","register","short","signed","static",
    		   "struct","typedef","union","unsigned","void","volatile","while"
    		   ,"break","continue","for","if","sizeof","switch","return","default","else"};
    
  2. open and read the file?:

void getNum(char *s,int grade){
	queue<int> q;
	ifstream infile;
	infile.open(s,ios::in);
	if (!infile){
		printf("file opened failure!!!");
		return ; 
	}
  1. To find the switch and case numbers?:
	string temp;
	bool judgeswitch=false;
	int cntcase;
	while (!infile.eof()){
		infile>>temp;
		//cout<<temp<<endl;
		for (int i=0;i<32;i++){
			if (i<22){
				if (temp==words[i]){
					mp[temp]++;
					if (temp=="case"&&judgeswitch)   cntcase++;
				}   
			}
			else{
				if (temp.substr(0,words[i].size())==words[i]){
					if (temp.size()==words[i].size()){
						mp[words[i]]++;
						if (words[i]=="switch"){
							judgeswitch=true;
							cntcase=0;
						} 
						else if (words[i]=="default"){
							judgeswitch=false;
							q.push(cntcase);
						}  
					}   
					else if (temp[words[i].size()]=='('||temp[words[i].size()]==';'||temp[words[i].size()]==':'
					||temp[words[i].size()]=='{'){
						mp[words[i]]++;
						if (words[i]=="switch"){
							judgeswitch=true;
							cntcase=0;
						}   
						else if (words[i]=="default"){
							judgeswitch=false;
							q.push(cntcase);
						}  
					}
				}
			}
		}
	}
  1. output and the main function?:
int total=0;
	for (auto v:mp){
		//output all the keywords
		//cout<<v.first<<" : "<<v.second<<endl;
		//calculate the sum
		total+=v.second;
	}
	cout<<"total num:"<<total<<endl;
	if (grade==2){
		cout<<"switch num: "<<q.size()<<endl;
		cout<<"case num: ";
		while (!q.empty()){
			cout<<q.front()<<" ";
			q.pop();
		}
	}
}
int main(){
	char url[100];
	int grade;
	cout<<"Enter the file path and judgment level:"<<endl;  // in.txt level 2
	cin>>url>>grade;
	getNum(url,grade);
	return 0;
}
  1. The output?

请添加图片描述

The entire code


#include<bits/stdc++.h>
using namespace std;
map<string,int> mp;
string words[32]={"auto","case","char","const","do",
		   "double","enum","extern","float","goto",
		   "int","long","register","short","signed","static",
		   "struct","typedef","union","unsigned","void","volatile","while"
		   ,"break","continue","for","if","sizeof","switch","return","default","else"};

void getNum(char *s,int grade){
	queue<int> q;
	ifstream infile;
	infile.open(s,ios::in);
	if (!infile){
		printf("file opened failure!!!");
		return ; 
	}
	string temp;
	bool judgeswitch=false;
	int cntcase;
	while (!infile.eof()){
		infile>>temp;
		//cout<<temp<<endl;
		for (int i=0;i<32;i++){
			if (i<22){
				if (temp==words[i]){
					mp[temp]++;
					if (temp=="case"&&judgeswitch)   cntcase++;
				}   
			}
			else{
				if (temp.substr(0,words[i].size())==words[i]){
					if (temp.size()==words[i].size()){
						mp[words[i]]++;
						if (words[i]=="switch"){
							judgeswitch=true;
							cntcase=0;
						} 
						else if (words[i]=="default"){
							judgeswitch=false;
							q.push(cntcase);
						}  
					}   
					else if (temp[words[i].size()]=='('||temp[words[i].size()]==';'||temp[words[i].size()]==':'
					||temp[words[i].size()]=='{'){
						mp[words[i]]++;
						if (words[i]=="switch"){
							judgeswitch=true;
							cntcase=0;
						}   
						else if (words[i]=="default"){
							judgeswitch=false;
							q.push(cntcase);
						}  
					}
				}
			}
		}
	}
	int total=0;
	for (auto v:mp){
		//output all the keywords
		//cout<<v.first<<" : "<<v.second<<endl;
		//calculate the sum
		total+=v.second;
	}
	cout<<"total num:"<<total<<endl;
	if (grade==2){
		cout<<"switch num: "<<q.size()<<endl;
		cout<<"case num: ";
		while (!q.empty()){
			cout<<q.front()<<" ";
			q.pop();
		}
	}
}
int main(){
	char url[100];
	int grade;
	cout<<"Enter the file path and judgment level:"<<endl;  // in.txt level 2
	cin>>url>>grade;
	getNum(url,grade);
	return 0;
}

🎄Summarize this assignment

  • I gained new knowledge on how to use GitHub,created my own GitHub page. ?(′▽`)

  • wrote code in the process of consolidating and reviewing the previous courses. After relearning, I found many deficiencies and did not grasp many details in place. ( ?? ω ?? )y

  • Learned how to draw a flow chart with markdown and plan in advance with PSP form, which greatly improved the efficiency

  • I feel very guilty for not completing the last two levels of questions, and my ability still needs to be improved. `(>﹏<)′

  • The knowledge points of file flow need to be further strengthened. The reason why we choose to use C + + is that the knowledge of Java is not proficient enough and needs to be further study.

在这里插入图片描述

  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2021-09-24 10:31:00  更:2021-09-24 10:31:50 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 15:38:09-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码